Python 我的discord.py机器人不能使用任何命令。发生了什么事?

Python 我的discord.py机器人不能使用任何命令。发生了什么事?,python,discord,discord.py,bots,Python,Discord,Discord.py,Bots,我有一个discord bot,它有两个简单的函数(client.event with client=discord.client()),最近我一直在尝试为一个音乐bot编写命令,但很明显,这个bot甚至不响应最简单的命令。例如: import discord from discord.ext import commands client = discord.Client() bot = commands.Bot(command_prefix='!') @bot.command() asy

我有一个discord bot,它有两个简单的函数(client.event with client=discord.client()),最近我一直在尝试为一个音乐bot编写命令,但很明显,这个bot甚至不响应最简单的命令。例如:

import discord
from discord.ext import commands

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


@bot.command()
async def hello():
    print("Hello") #So when I type !hello in a channel I want "Hello" written in the console as prove that the bot is responding


@client.event
async def on_ready():
    print("Online.") #Just simple if the bot is online
函数client.event当然可以工作,但bot.command()函数不会以任何方式作出反应。有人能帮我吗?我真的要打破我所有的一切。

试试这个:

导入不一致
从discord.ext导入命令
bot=commands.bot(命令前缀=“!”)
@bot.command()
异步def hello(ctx):
打印(“你好”)
@机器人事件
_ready()上的异步定义:
打印(“在线”)
bot.run(“令牌”)

首先,为什么要同时定义客户端和bot?其次,代码中没有
bot.run()
。第三,您必须始终在
@bot.command

中提供
ctx
,您可以使用
discord.Client
commands.bot
,但不能同时使用它们。如果查看代码,您将使用
bot.command()
来装饰命令,但在文件的末尾运行的是
client
。如果您需要命令,我建议您使用
命令.Bot

导入不一致
从discord.ext导入命令
bot=commands.bot(命令前缀=“!”)
@bot.command()
异步def hello(ctx):
打印(“你好”)
@机器人事件
_ready()上的异步定义:
打印(“在线”)
bot.run(“XXX”)