为什么我不能使用命令前缀?

2024-06-01 00:23:47 发布

您现在位置:Python中文网/ 问答频道 /正文

每次我尝试使用commands.Bot(command_prefix=''),程序都会将其作为错误读取。例如,使用下面的代码,它会

Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "-ping" is not found Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "ping" is not found

在我想让机器人说的话(Pong!)在服务器中发送2次或更多次之前,重复了几次

\我想可能是循环?我不确定,但我让它工作过一次,但我等待的时间越长,每次使用命令它都会发送更多的响应-这是我最后一次尝试时发出的16'Pong。。。对此我能做些什么吗?\

我怎样才能解决这个问题

from discord.ext import commands
client = commands.Bot(command_prefix='-')

@client.event
async def on_ready():
    print("Bot is ready for use...")

@client.command()
async def ping(ctx):
    await ctx.send('Pong')

client.run('TOKEN')

Tags: inclientnoneprefixisbotexceptionping
1条回答
网友
1楼 · 发布于 2024-06-01 00:23:47

问题不在于前缀,而在于您忘记了client.command装饰符后面的括号:

from discord.ext import commands
client = commands.Bot(command_prefix='-')

@client.event
async def on_ready():
    print("Bot is ready for use...")

@client.command()
async def ping(ctx):
    await ctx.send('Pong')

client.run('TOKEN')

client.event装饰器没有任何参数,因此不需要括号,但是client.command()可以有类似name=brief=description=aliases的参数。。。所以你需要括号。^^

相关问题 更多 >