【问题标题】:Why can't I use command prefixes?为什么我不能使用命令前缀?
【发布时间】:2020-10-27 14:51:23
【问题描述】:

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

忽略命令中的异常无:discord.ext.commands.errors.CommandNotFound:命令“-ping”不是 在命令无中发现忽略异常: discord.ext.commands.errors.CommandNotFound:命令“ping”不是 找到了

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

\我认为它可能是循环的?我不确定,但我让它工作了一次,但是我等待的时间越长,每次使用它发送更多响应的命令? -我上次尝试时发送了 16 'Pong's...对此我有什么办法吗?\

我该如何解决这个问题?

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

【问题讨论】:

    标签: python command discord discord.py discord.py-rewrite


    【解决方案1】:

    问题不在于你的前缀,你只是忘记了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 等参数,所以你需要括号。 ^^

    【讨论】:

    • 我认为它可能正在循环播放?我不确定,但我让它工作了一次,但是我等待的时间越长,每次使用它发送更多响应的命令? -它发送了 16 'Pong!'s 最后一次我尝试...对此我能做些什么吗?
    • 不应该这样,能给我一个完整代码的链接吗?
    • 那只是我尝试 .command() 我的真实代码很长,但同样的问题发生了。 (我根据他们的心情(?)对一堆引号进行了排序,命令应该根据我选择的心情给我一个随机引号 - 如果这有意义吗?)paste.pythondiscord.com/gazalobiye.sql
    猜你喜欢
    • 2023-03-30
    • 2017-01-02
    • 2018-07-02
    • 1970-01-01
    • 2020-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-30
    相关资源
    最近更新 更多