首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NEXTCORD按钮

NEXTCORD按钮
EN

Stack Overflow用户
提问于 2022-02-08 07:36:10
回答 1查看 2.2K关注 0票数 0

为什么这段代码不能工作?代码的目的是让按钮永远工作,因为过了一段时间,它就停止工作了,有人能给我一些顽皮的帮助吗?xD

代码语言:javascript
复制
@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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-13 20:51:08

不能在命令中构建类。

代码语言:javascript
复制
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)

确保您的类保持在实际命令之上。这样就行了。

代码语言:javascript
复制
@client.command()
async def teste(ctx, role : nextcord.Role):
    view = buttons()
    await ctx.send("teste", view=view)
    await view.wait()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71030062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档