Discord 命令机器人没有响应 (python)

Discord command bot doesn't responde (python)

我的 discord 机器人有问题:当我在 discord $ping 上输入时,他没有回应我的乒乓球,我不知道为什么,我只是检查机器人有管理员角色,这样他就可以写,我正在使用 VsCode,他没有给我任何错误。
这是代码

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")

问题是,您使用 bot.command 定义命令,但您只执行 client.run。要解决此问题,请选择客户端或机器人,但不能同时选择两者,例如,如果您选择机器人,则如下所示:

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)

也不要使用请求,因为它是阻塞的。