Reputation: 309
For example, when someone DMs my bot, it says "hello" or "why are you trying to DM a bot..?" I tried this with this code:
@client.event
async def on_message(message: discord.Message):
if message.guild is None and not message.author.bot:
with open('dmresponses.txt') as input_file:
long_list = [line.strip() for line in input_file]
await message.author.send(random.choice(long_list))
and it worked. But, my commands like "m!help" and "m!about" stopped working. What is the proper way of doing this?
Upvotes: 3
Views: 362
Reputation: 6944
When you add an on_message
event, you need to process the commands:
@client.event
async def on_message(message): # no need to define the type
await client.process_commands(message)
# rest of the code here
References:
Bot.process_commands()
- "Without this coroutine, none of the commands will be triggered. If you choose to override the on_message()
event, then you should invoke this coroutine as well."on_message
Upvotes: 2