Reputation: 53
Hello im trying to communicate with my bot discord but its doesnt answer the bot is online but no answer here the following code :
import discord
client = discord.Client(intents=discord.Intents.default())
client.run("token")
@client.event
async def on_message(message):
if message.content == "ping":
await message.channel.send("pong")
Upvotes: 0
Views: 112
Reputation: 111
Having your bot to answer to sent messages requires the message_content intent.
With intents=discord.Intents.default()
following intents are DISABLED:
You can now enable all mentioned intents or only specific intents. If you want to send a message, in response to a sent message, you need the intent self.message_content
.
You can also add all intents to avoid any problems with them in the future (Note that after a certain amount of Discord servers you need to apply to use all privileged intents.)
intents = discord.Intents.all()
client = discord.Client(intents=intents)
You should consider activating the intents:
Visit the developer portal > choose your app > Privileged Gateway Intents.
For further programming in Discord.py, consider reading the docs, as there is a new version of Discord.py.
Upvotes: 1
Reputation: 5647
The message_content
intent mentioned above is necessary, but it's not the only thing wrong here.
When you call client.run()
, nothing below it will execute until the client goes down. This means that your on_message
event is never created. client.run()
should be the very last line in your file.
Upvotes: 1
Reputation: 416
You need to enable the message content intent. add this in your code under your intents definitions
intents.message_content = True
then head to the developer dashboard
and enable the Message Content
at the Privileged Intents
after that your code should work ;-)
Upvotes: 2