【发布时间】:2020-09-16 15:39:13
【问题描述】:
我现在正在我的 discord 机器人中处理 8balls 功能。我希望它在人们只调用“!8balls”但在频道中没有输入“问题”时做出反应。它应该在通道中打印出一行而不是什么都不做。
@client.command('8balls')
async def _8balls_1(ctx):
await ctx.send(':warning:Please enter a question after the command and seperate them with a space.')
@client.command('8balls')
async def _8balls(ctx, *, question):
responses = ["It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful."]
await ctx.send(f'Question:\"{question}\"\n Response:\"{random.choice(responses)}\"')
我试图通过这样的写作来实现多态性。不幸的是,它不起作用。我该如何解决?
【问题讨论】:
-
忽略命令 _8balls 中的异常:回溯(最后一次调用):文件“/home/zyck/anaconda3/lib/python3.7/site-packages/discord/ext/commands/bot.py ”,第 903 行,在调用 await ctx.command.invoke(ctx) 文件“/home/zyck/anaconda3/lib/python3.7/site-packages/discord/ext/commands/core.py”,第 847 行,在调用 await self.prepare(ctx) 文件“/home/zyck/anaconda3/lib/python3.7/site-packages/discord/ext/commands/core.py”,第 784 行,准备等待 self._parse_arguments(ctx)
-
文件“/home/zyck/anaconda3/lib/python3.7/site-packages/discord/ext/commands/core.py”,第 690 行,在 _parse_arguments 中转换 = await self.transform( ctx,参数)文件“/home/zyck/anaconda3/lib/python3.7/site-packages/discord/ext/commands/core.py”,第 535 行,在转换中提高 MissingRequiredArgument(param) discord.ext.commands。 errors.MissingRequiredArgument:问题是缺少的必填参数。
-
当我隐藏 _8balls(ctx) 函数时出现这些错误行。
标签: python bots discord.py