python - 为什么我不能使用命令前缀?
问题描述
每次我尝试使用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')
解决方案
问题不是来自你的前缀,你只是在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
, ... 这样的参数,所以你需要括号。^^
推荐阅读
- java - 如何基于时间多次显示textView
- azure - Azure Blob 存储 - 下载和上传时的内容类型设置
- android - 如何从 imageView 获取图像?
- python - 比较 3 个数组以查找模式和格式化输出
- google-apps-script - 有没有办法使用 Google CalendarApp 脚本从谷歌日历中获取预约空档数据?
- python - 使用 Python 3 和 Numpy 显示每个元素相对于列总数的百分比值的最佳方法是什么?
- asp.net-web-api - 用于批处理操作的 HTTP 动词
- python-3.x - 如何识别变量并从python中的文本文件中分配值?
- laravel - 无法在 Laravel 中添加外键
- android - 在我更改应用程序包名称之前,Android Webview 不会加载网站