为啥我不能使用命令前缀?
Posted
技术标签:
【中文标题】为啥我不能使用命令前缀?【英文标题】: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')
【问题讨论】:
【参考方案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以上是关于为啥我不能使用命令前缀?的主要内容,如果未能解决你的问题,请参考以下文章
为啥我不能使用 MobileFirst 命令行工具添加合适的服务器配置文件?
为啥我不能使用 gcloud 的批处理文件连续运行 2 个命令