我一直在尝试编写一个 Discord 机器人并制作一个 8ball,但它告诉我没有定义随机数。
@client.command(aliases=['8ball'])
async def _8ball(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}\nAnswer: {random.choices(responses)}')
我得到了错误
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'random' is not defined
我的代码有问题吗?这是我第一次编码。