0

somehow my bot is not responding to commands in servers, but he is responding in DM. Someone can help me?

My code:

import discord
from dotenv import load_dotenv
token = "****"
load_dotenv()
client = discord.Client(intents=discord.Intents.default() )

@client.event
async def on_ready():
    print(f"Bot logged in as {client.user}")

@client.event
async def on_message(message):
    if message.author != client.user:
        if message.content =='$hi':
            d = "hi"
            await message.channel.send(d)

client.run(token)
0

2 Answers 2

0

The default Intent value is 3243773 which doesn't have GUILD_MEMBERS, GUILD_PRESENCES and MESSAGE_CONTENT intents.
One of these (most likely MESSAGE_CONTENT) means that your bot isn't sent the content of messages in servers. You can test this by just printing message.content and you should just see empty messages.
To fix you can use discord.Intents.all() which has all intents

# add some/all of these to see what works
client = discord.Client(intents = discord.Intents.all())

quick note: you can make your code cleaner by removing an indent level

@client.event
async def on_message(message):
    if message.author == client.user: return;
    if message.content =='$hi':
        d = "hi"
        await message.channel.send(d)
0
import discord
token = "BOT_TOKEN"

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

@client.event
async def on_ready():
    print(f"Bot logged in as {client.user}")

@client.event
async def on_message(message):
    if message.author != client.user:

        if message.content == '$hi':
            d = "hi"
            await message.channel.send(d)

client.run(token)

And enable all Privileged Gateway Intents in Discord Developer Poral > App Name > Bot > Privileged Gateway Intents.

https://i.sstatic.net/V2EI6.png

Not the answer you're looking for? Browse other questions tagged or ask your own question.