【发布时间】:2021-08-23 06:50:32
【问题描述】:
我知道 - 这个标题有很多问题,但大多数是针对 Dark Sky 的,或者与我的问题不同。
class Counter(discord.ui.View):
@discord.ui.button(label='0', style=discord.ButtonStyle.red)
async def counter(self, button: discord.ui.Button, interaction:
discord.Interaction):
number = int(button.label)
button.label = str(number + 1)
if number + 1 >= 5:
button.style = discord.ButtonStyle.green
await interaction.message.edit(view=self)
view = Counter()
await ctx.send('Press to increment', view=view)
错误信息:
File "main.py", line 27
await ctx.send('Press to increment', view=view)
^
SyntaxError: 'await' outside function
我对 python 很陌生,完全不知道为什么会这样。任何帮助将不胜感激!
【问题讨论】:
-
最后一行不在异步函数内,放在异步函数内就行了
-
await是高级 Python,你说你是 Python 新手。这很难提供帮助。 -
完整代码请...
-
@VPfB 我认为事实是,很多人正在使用 Discord.py 进入 python(和一般编程),这需要学习至少对异步编程的表面理解。说它太先进对人们没有帮助——总会有人潜入深渊,而且这可能是最好的学习方式
标签: python discord.py