I am trying to make it so a discord bot won't react to a certain user when they make say an edit on a message, however it doesn't quite work. My current code is
from discord.ext import commands
id = id
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_message(message):
if message.author.id == id:
pass
else:
@bot.event
async def on_message_edit( before, after):
await before.channel.send(
f'Before: {before.content}\n' f'After: {after.content}'
bot.run('token')
I have to do this because I just put if message.author.id == id in the on_message_edit it would return as false. I also tried to also use variables like if message.author.id == id then something = True, but it just won't work. But this doesn't quite work either, any suggestions as to how I could fix this?
CodePudding user response:
First of all, avoid naming strings like id
since it's used by discord.py already and can be confusing for python. I've changed it for banned_id
just for this example.
Secondly, message.author.id
is an integer value, so make sure you compare it to another integer value. If you make something like:
banned_id = 142345353455345
python treats it just like a string of characters, not a number. You can make it a number using int()
.
For me this code works just fine:
@bot.event
async def on_message_edit(before, after):
banned_id = int(YOUR_ID_HERE)
if before.author.id == banned_id:
await before.channel.send("you wish")
else:
await before.channel.send(f'Before: {before.content}\n' f'After: {after.content}')