【问题标题】:Discord.py interaction bug(or i am just dump)Discord.py 交互错误(或者我只是转储)
【发布时间】:2022-06-11 00:39:11
【问题描述】:

我正在尝试使用天气 API 制作一个简单的不和谐机器人。

但一个错误(或什么)不会让我

@bot.command(name='teste')
async def button(ctx):

    try:

        msg = await ctx.send('Escolha a forma preferivel para inserir a localização',
                             components=[[Button(label="Cordenadas", custom_id="cord", style=4),
                                         Button(label="Cidade", custom_id="button2", style=1)]],
                             delete_after=60)
        cords = await bot.wait_for("button_click", check=lambda i: i.custom_id == "cord")
        cord = len(str(cords.user))
        await ctx.message.delete()
        await msg.delete()
        api_key = 'its my litle secret'
        if cord > 0:
            await ctx.send('informe as cordenadas desejadas(Latitude e Longitude nessa ordem), ex:"$38.9041 -77.0171"')

        city = await bot.wait_for("button_click", check=lambda i: i.custom_id == "button2")
        cit = len(str(cords.user)) 

当我运行代码时,按钮正常显示,当我点击绳索按钮时,他检测到,但是当我点击城市按钮时,他没有检测到,我发现第一个 await bot.wait_for 只是不要让下一个被检查,所以当我点击城市时,他检查cord.bot.wait_for 并且不能继续下一个。谁能告诉我发生了什么并帮我解决这个问题?

不要介意葡萄牙语文本。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    我在另一篇文章中找到了此代码,而不是 wait_for,它有一个 on_button_click。这也可以编辑用于多种用途。我添加了一个 sn-p 来说明如何设置。

    @bot.event
    async def on_button_click(interaction):
        if interaction.component.label.startswith("Default Button"):
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      相关资源
      最近更新 更多