-1

i have a problem with my discord bot: when i type on discord $ping he doesn't response me pong and i don't know why, i just check the bot have the admin role so he can write, i'm using VsCode and he didn't give me nothing error.
Here is the code

import discord
from discord.ext import commands
import requests
import json
import random

client = discord.Client()
bot = commands.Bot(command_prefix='$')

@bot.command()
async def ping(ctx):
    await ctx.channel.send("pong")

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

client.run("XXXXXXXXXXXXXXXXXXXXXXX")
3
  • You are mixing client and bot, do not do that... This is why the command is not working. Commented Apr 29, 2021 at 9:13
  • So what i need to delete? client =discord.Client() andall@client event? Commented Apr 29, 2021 at 9:15
  • Yes, you can delete client = discord.Client() and use bot.event and bot.command(). To run the bot use bot.run("Token") Commented Apr 29, 2021 at 9:16

1 Answer 1

2

The problem is, that you are defining the command with bot.command, but you only do client.run. To fix this, either choose a client, or a bot, but not both, like this if you choose bot for example:

import discord
from discord.ext import commands
import json
import random

bot = commands.Bot(command_prefix='$')

@bot.command()
async def ping(ctx):
    await ctx.channel.send("pong")

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

Also don't use requests, since it's blocking.

Sign up to request clarification or add additional context in comments.

2 Comments

@Luigi2201 Could you accept the answer (with the green checkmark) if it worked for you, so others can quickly see that it works?
I just do it now

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.