8ball 嵌入命令无法启动

时间:2021-05-01 19:53:32

标签: discord.py

我正在尝试重新执行我的机器人的 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.',
                 'No.',
                 '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.']
    responses = random.choice(responses)
    embed=discord.Embed(title="8ball", description="Ask the 8ball!", color=discord.Color.dark_purple())
    embed.add_field(name="Q: {question}", value="A: {responses}", inline=False)
    await ctx.send(embed=embed)

但是python文件拒绝启动,并返回

  File "C:\Users\r00t_technologies\Documents\bot\enigmatic-peak-21114\bot_development.py", line 135
    await ctx.send(embed=embed)
    ^
SyntaxError: 'await' outside function

有人能帮我解决这个问题吗?

编辑:没关系,我只是个白痴,看错了线路,很抱歉给您带来不便(我对此有点缺乏经验)

2 个答案:

答案 0 :(得分:0)

我不知道为什么错误说在函数外等待,但它已经在函数中,我编辑了你的代码并在我的机器人中测试了它并且它工作得很好。

所以试试这个:

@client.command()
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.',
                 'No.',
                 '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.']
    responses = random.choice(responses)
    embed=discord.Embed(title="8ball", description="Ask the 8ball!", color=discord.Color.dark_purple())
    embed.add_field(name="Q: " + question, value="A:" + responses, inline=False)
    await ctx.send(embed=embed)

答案 1 :(得分:-1)

您需要在 aliases = 中拥有多个别名。试试 [‘8ball’, ‘8b’]