1

I have multiple discord bots but suddenly, they all just stopped responding to my commands. I copied this code from online to see if there was a problem with my code, but this doesn't seem to work either. When I type in "$hello", nothing happens. The bot goes online when it runs but doesn't do anything aside from that. I have double-checked my python is up to date, the bot has server roles and permissions, tried it on multiple servers, and ensured that the bot has admin permissions on the discord developer portal. I'm not sure what else could be wrong. It may just be a coincidence but I installed some discord-ui packages when the problem occurred. However, I did uninstall it and the bot still does not work. And yes, my real token is in the code.

import discord

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

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

    if message.content.startswith('$hello'):
        await message.send('Hello!')

client.run('MY TOKEN IS HERE')

2 Answers 2

0

If you copy it from somewhere else, they probably don't do it right (proof: here and here). After checking the docs (to check is my guess is right), it's await message.channel.send('things'), not await message.send('Hello!'). So to fix it, change to this:

import discord

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

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

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

client.run('MY TOKEN IS HERE')

PS: Because you only show the copied code, I only answer that code

1
  • Also about the all bots not responding, check is your bots have message intents (and your code). You should make a slash command btw.
    – BrainFl
    Mar 18, 2022 at 10:56
-1

It because of Message Intent. Your bot won't see message content if it is disabled. Of course you can just turn it on but it is recommended to use slash commands. discord.py has no support for slash commands, so I'll recommend to use pycord.

Here is short example of slash command

import discord

bot = discord.Bot()

@bot.slash_command()
async def hello(ctx, name: str = None):
    name = name or ctx.author.name
    await ctx.respond(f"Hello {name}!")

bot.run("token")

Pycord documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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