首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当单击按钮时,如何发送模式?

当单击按钮时,如何发送模式?
EN

Stack Overflow用户
提问于 2022-09-19 06:49:19
回答 1查看 71关注 0票数 -1

我试图发送一个模式时,“询问”按钮是从嵌入式点击。

错误消息:

代码语言:javascript
复制
AttributeError: 'Button' object has no attribute 'response'
代码语言:javascript
复制
class AskModal(nextcord.ui.Modal):
    def __init__(self):
        super().__init__(
            "Ask",
        )
    
        self.emQuestion = nextcord.ui.TextInput(label = "Question", required = True, placeholder = "What level shall I reach to stay in the group?", style = nextcord.TextInputStyle.paragraph)
        self.add_item(self.emQuestion)

    async def callback(self, interaction: nextcord.Interaction) -> None:
        question = self.emQuestion.value
        channel = bot.get_channel(1017234639770894377)
        questionmsg = (f"{question} ^ {interaction.user.id}")
        message = ("Your question has been sent!")

        await channel.send(questionmsg)

        return await interaction.response.send_message(message, ephemeral=True)

class askbutton(nextcord.ui.View):
    def __int__(self):
        super().__init__(
            "AskButton",
        )

    @nextcord.ui.button(label="Ask", style= nextcord.ButtonStyle.red, custom_id = "ask button")
    async def asks(self, interaction: nextcord.Interaction, button: nextcord.ui.Button):
        return await interaction.response.send_modal(AskModal())

@bot.command()
async def ask(ctx) :
    embed = nextcord.Embed(title="QNA", description="・You may ask a question by using the slash command `/ask`\n\n・You'll be notified that your question has been answered by receiving a ping in the <#928507764714651698> channel", color= 0x303136)
    await ctx.send(embed = embed, view = askbutton())

当按钮被点击时,询问按钮没有反应,我错过了什么吗?

EN

回答 1

Stack Overflow用户

发布于 2022-09-19 14:09:52

这是nextcord,不是discord.py。在nextcord中,按钮回调中参数的顺序是不同的。

Discord.py使用interaction, button,nextcord使用button, interaction。交换参数的顺序。

您的错误也说明了这一点--您正在调用interaction.response,但错误显示您调用了Button.response

不过,我会考虑改用discord.py 而不是.。

两个并排的官方例子:discord.py - 下弦.如果您想使用叉子,请确保查看正确的文档和示例。你不能把它们混在图书馆里。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73769454

复制
相关文章

相似问题

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