我开始在我的 Discord 机器人中编写一个命令,该命令使用户能够使用消息与机器人进行交互。然而,当我运行我的程序时,我遇到了这个错误:
在异步函数之外“等待”
我查看了其他帖子,这些帖子说缩进可以解决问题,但我在代码中使用了 while 循环。
@client.command()
async def Bot (ctx):
def Bot1():
while True:
Initiate = input ("Type in anything to start, type 'Quit' to end ")
if Initiate == 'Hello':
await ctx.send ("Hello there!")
elif Initiate == 'Quit':
break
else:
Responses = ['How are you doing today', 'What do you want to talk about', 'The bot is at your service']
Response = random.choose(Responses)
await ctx.send (Response)
await ctx.send (Bot1())
最佳答案
你的 Bot1 功能
def Bot1():
错误。
如果您在函数内使用 await
,在您使用的情况下,您必须:
async def Bot1():
在问题 2 之后编辑:
我认为你的问题是这一行
await ctx.send (Bot1())
这必须转换为
await ctx.send (Bot1)
或
await ctx.send (await Bot1())
关于python - 语法错误 : 'await' outside async function in Discord. py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70729414/