Reputation: 387
If I put this in main.py the bot is broken and no commands work but I don't get an error
@client.event
async def on_message(message):
if client.user.mentioned_in(message):
embed=discord.Embed(description='My prefix here is ?. You can see available commands by typing `?help`', color=0x850000)
await message.channel.send(embed=embed)
and If put this in cogs/commands.py, on_message
still doesn't work but other commands work. but I get this error everytime I type something into discord even without prefix
File "C:\Users\BUGA\Documents\VSCODE\Python Projects\activity role\cogs\commands.py", line 17, in on_message if client.user.mentioned_in(message): AttributeError: 'NoneType' object has no attribute 'mentioned_in'
@commands.Cog.listener()
async def on_message(self, message):
if client.user.mentioned_in(message):
embed=discord.Embed(description='My prefix here is ?. You can see available commands by typing ?help', color=0x850000)
await message.channel.send(embed=embed)
Upvotes: 0
Views: 390
Reputation: 2346
For your first piece of code, you can use await client.process_commands(message)
. You can have a look at the docs' Frequently Asked Questions for more information, but in simplicity:
@client.event async def on_message(message): # do whatever you needed to do in your on_message if client.user.mentioned_in(message): await message.channel.send("My prefix for this server is ?") await client.process_commands(message)
Refrences:
Upvotes: 1
Reputation: 396
From your error, client.user is evaluating as None. From the docs, client.user returns None if the user is not logged in. So check what client.user is returning, and then see if you can get a different result with a logged in user
Upvotes: 0