Reputation: 9
I have some problem when I try to create a bot
Here is a part of my code:
@client.event
async def on_message(message):
if message.author == client.user:
return
await client.process_commands(message)
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
general_channel = client.get_channel(874180398475804695)
await general_channel.send('I am ready',delete_after=10)
@client.event
async def on_message(message):
if any(word in message.content for word in rude_word):
await message.reply('Hey man, that word is not allowed here .',delete_after=2)
await message.delete()
@client.command(name='ping')
async def ping(message):
await message.reply('pong')
When I type command, the bot does not work.
BUT, if I remove the part of:
@client.event
async def on_message(message):
if any(word in message.content for word in rude_word):
await message.reply('Hey man, that word is not allowed here .',delete_after=2)
await message.delete()
The command works again.
Another situation, I remove :
@client.command(name='ping')
async def ping(message):
await message.reply('pong')
The bot still can works(delete message). However, when I combine these two, the @client.command
doesn't works. I have try my best to figure it out but still have no idea. What can I do to let the commands work?
Upvotes: 0
Views: 450
Reputation: 73
The issue is with on_message. You need to add await client.process_commands(message)
at the end of on_message
as mentioned here in the discord.py
FAQ.
Upvotes: 1