为什么这段代码不能工作?代码的目的是让按钮永远工作,因为过了一段时间,它就停止工作了,有人能给我一些顽皮的帮助吗?xD
@client.command()
async def teste(ctx, role : nextcord.Role):
class buttons(nextcord.ui.View(timeout = 0)):
def __init__(self):
super().__init__()
self.value = None
@nextcord.ui.button(label = "teste", style = nextcord.ButtonStyle.blurple)
async def teste(self, button : nextcord.ui.Button, interaction : nextcord.Interaction):
if role in interaction.user.roles:
await interaction.user.remove_roles(role)
else:
await interaction.user.add_roles(role)
view = buttons()
await ctx.send("teste", view = view)
await view.wait()发布于 2022-02-13 20:51:08
不能在命令中构建类。
class buttons(nextcord.ui.View(timeout = 0)):
def __init__(self):
super().__init__()
self.value = None
@nextcord.ui.button(label = "teste", style = nextcord.ButtonStyle.blurple)
async def teste(self, button : nextcord.ui.Button, interaction : nextcord.Interaction):
if role in interaction.user.roles:
await interaction.user.remove_roles(role)
else:
await interaction.user.add_roles(role)确保您的类保持在实际命令之上。这样就行了。
@client.command()
async def teste(ctx, role : nextcord.Role):
view = buttons()
await ctx.send("teste", view=view)
await view.wait()https://stackoverflow.com/questions/71030062
复制相似问题