我正在尝试创建一个 Discord 机器人并向其添加一些命令,但它似乎不起作用。 我添加了 print 语句来确定命令是否已添加,但它返回 None。在 Discord 频道中调用“!hello”会引发 CommandNotFound。
import discord
from discord.ext import commands
client = commands.Bot(command_prefix="!")
TOKEN = [some token]
@client.command
async def hello(ctx, arg):
await ctx.channel.send(arg)
print(client.get_command("hello"))
client.run(TOKEN)
那是因为你在
@client.command
之后缺少括号,只需添加 ()
即可,如下所示:
@client.command()
ctx.channel.send() 需要替换为 ctx.send() 正如 loloToster 刚才所说,@client.command 后面需要 () 所以最终的代码是:
from discord.ext import commands
client = commands.Bot(command_prefix="!")
TOKEN = [some token]
@client.command()
async def hello(ctx, arg):
await ctx.send(arg)
print(client.get_command("hello"))
client.run(TOKEN)