'Anti Ghostping event
I tried to make a Anti Ghostping event but it don't works and show no errors
Code:
@bot.event
async def on_message_delete(message, member: discord.Member = None):
if member == None:
return
else:
print(member.name)
ghostping = discord.Embed(title=f'GHOSTPING', color=0xFF0000, timestamp=message.created_at)
ghostping.add_field(name='**Name:**', value=f'{message.author} ({message.author.id})')
ghostping.add_field(name='**Message:**', value=f'{message.content}')
ghostping.set_thumbnail(
url='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTXtzZMvleC8FG1ExS4PyhFUm9kS4BGVlsTYw&usqp=CAU')
try:
await message.channel.send(embed=ghostping)
except discord.Forbidden:
try:
await member.send(embed=ghostping)
except discord.Forbidden:
return
Solution 1:[1]
Do this:
@bot.event
async def on_message_delete(message):
if len(message.mentions) == 0:
return
else:
print(message.author.name)
ghostping = discord.Embed(title=f'GHOSTPING', color=0xFF0000, timestamp=message.created_at)
ghostping.add_field(name='**Name:**', value=f'{message.author} ({message.author.id})')
ghostping.add_field(name='**Message:**', value=f'{message.content}')
ghostping.set_thumbnail(
url='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTXtzZMvleC8FG1ExS4PyhFUm9kS4BGVlsTYw&usqp=CAU')
try:
await message.channel.send(embed=ghostping)
except discord.Forbidden:
try:
await message.author.send(embed=ghostping)
except discord.Forbidden:
return
EDIT #1: I forgot to change member
to message.author
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |