Не работают кнопки discord.py
У меня есть шаблонный код, который я добавил в своего бота:
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
bot.remove_command("help")
@bot.event
async def on_ready():
print("Module loaded!")
DiscordComponents(bot, change_discord_methods=True)
@bot.command()
async def test(ctx):
embed = discord.Embed(title = 'Testing')
await ctx.send(embed=embed, components = [Button(style = ButtonStyle.green, label = 'Button 1', custom_id="butt1"),
Button(style = ButtonStyle.red, label = 'Button 2', custom_id="butt2")])
interaction = await bot.wait_for("button_click", check = lambda i: i.custom_id == "butt1")
await interaction.send(content = "Button 1 clicked!")
interaction = await bot.wait_for("button_click", check = lambda i: i.custom_id == "butt2")
await interaction.send(content = "Button 2 clicked!")
bot.run("TOKEN")
Проблема в том, что при нажатии на одну из кнопок Discord пишет "Ошибка взаимодействия", но в консоли никакой ошибки не выходит. Пожалуйста, помогите исправить.
Ответы (1 шт):
Автор решения: Telmor
→ Ссылка
Смотри. в interaction(который я делаю обычно responce обычно делается проверка на клин и на автора клика. Что бы кнопка выводить сообщение по нажатию кнопки измени код на:
@bot.command()
async def test(ctx):
await ctx.send(embed = discord.Embed(title='test'),
components = [
Button(style = ButtonStyle.gray, label ='Button1', custom_id="1"),
Button(style = ButtonStyle.gray, label ='Button2', custom_id="2")
])
responce = await bot.wait_for('button_click', check=lambda message: message.author == inter.author)
if responce.component.id == '1': #вроде так, id не пользуюсь
await ctx.send(embed = discord.Embed(title='1'))
На примере моего кода думаю ты сможешь разобраться со своей ошибкой(если кнчн она актуальна)