有没有办法用 nextcord 把链接放在按钮中?

Is there any way to put links in buttons with nextcord?

所以我尝试制作一个带有 link 的按钮,以根据命令对用户进行 rickroll。我希望只有一个按钮,但出现了两个。只有一个按钮实际打开了link。 我的 class 代码:

class Rickroller(nextcord.ui.View):
    def __init__(self):
        super().__init__()
        self.add_item(nextcord.ui.Button(style=nextcord.ButtonStyle.link, url='https://www.youtube.com/watch?v=dQw4w9WgXcQ', label="Get rickrolled"))
        self.value = None
        @nextcord.ui.button(label='get rickrolled', style=nextcord.ButtonStyle.blurple)
        async def rickroll(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
            await interaction.response.send_message('got rickrolled', ephemeral=False)
            self.value = True
            self.stop()

我的命令代码:

@bot.command()
async def rickroll(ctx):
    view = Rickroller()
    await ctx.send('rickroll?', view=view)
    await view.wait()
    if view is None:
        return
    elif view.value is True:
        await ctx.send("nothing")#made that for debugging
    else:
        await ctx.send('Would be too funny to get rickrolled by a bot, huh?')

问题是,您添加了两个按钮,一个使用 self.add_item 具有 link 样式,另一个使用装饰器没有 link 样式。您可能想要实现的是按钮打开 link 并以不和谐的方式执行某些操作,这是不可能的。要修复这两个按钮,请删除您使用装饰器添加的按钮:

class Rickroller(nextcord.ui.View):
    def __init__(self):
        super().__init__()
        self.add_item(nextcord.ui.Button(style=nextcord.ButtonStyle.link, url='https://www.youtube.com/watch?v=dQw4w9WgXcQ', label="Get rickrolled"))
        self.value = None

这将是您的视图的固定代码。