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

错误消息:
AttributeError: 'Button' object has no attribute 'response'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())当按钮被点击时,询问按钮没有反应,我错过了什么吗?
发布于 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 - 下弦.如果您想使用叉子,请确保查看正确的文档和示例。你不能把它们混在图书馆里。
https://stackoverflow.com/questions/73769454
复制相似问题