Discord bot (py) Dont't reply to messages on any servers but reply to direct dms

Viewed 36

Discord bot (py) Dont't reply to messages on any servers but reply to direct dms

I build a discord Bot with python using discord.py an as I write the (example $hello), it reply only on private dms not on any servers messages. I olready gived the bot admin on the server but still not doing anything.

My py code is:

intents = discord.Intents.default()
intents.members = True

client = discord.Client(intents=intents)

async def on_message(message): 
     if message.content.startswith('$hello'):
           print(message.content)
           await message.channel.send('Hello')

client.run(token)

Also it not write anything to the console if I send the message on a dc server.

There is no firewall rule what can cose the issue I olrady chacked it.

2 Answers

Just as a quick hint: according to discords API reference to the "on_message()" function you need to set Intents.messages to True. In your case this would be

intents.messages = True

I did not test this code, but it's what I read from discords docs. In the future you might want to have a look at it https://discordpy.readthedocs.io/en/stable/

I hope I could help you with this quick answer :)

Make sure that the bot intents are toggled in the Developer Portal

If you had it enabled, you can try enabling all the intents and then putting this in the intents parameter

client = discord.Client(intents=discord.Intents().all())

The code will probably look like this

import discord

client = discord.Client(intents=discord.Intents().all())

async def on_message(message): 
     if message.content.startswith('$hello'):
           print(message.content)
           await message.channel.send('Hello')

client.run(token)
Related