我正在尝试重做我的机器人的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有谁能帮我解决这个问题吗?
编辑:不要紧,我只是个笨蛋,看错了线,很抱歉给你带来不便(我在这方面有点经验不足)
发布于 2021-05-02 08:58:27
我不知道为什么这个错误说在函数外等待,但它已经在函数中了,我编辑了你的代码,我在我的Bot中测试了它,它工作得很好。
所以试试这个:
@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)发布于 2021-05-02 12:14:33
在aliases =中需要有多个别名。尝试“8ball”,“8b”
https://stackoverflow.com/questions/67350325
复制相似问题