При нажатии на кнопку пишет "ошибка взаимодействия" ( discord py )
@bot.command()
async def test(ctx):
msg = await ctx.send(
embed = discord.Embed(title = 'Вы точно хотите перевести деньги?'),
components = [
Button(style = ButtonStyle.green, label = 'Да'),
Button(style = ButtonStyle.red, label = 'Нет')
])
responce = await bot.wait_for('button_click')
if responce.component.label == 'Да':
await responce.respond(content = 'Деньги успешно переведены!')
else:
await responce.respond(content = 'Вы отменили перевод.')
Ответы (1 шт):
Автор решения: JiMoon - Python
→ Ссылка
- Вы импортировали нужную библиотеку?
import discord_components
from discord_components import Button, ButtonStyle, DiscordComponents
- Вы написали строчку ниже в функцию
on_ready()? Если она у вас вообще есть. Хотя, как ее в боте не может быть.
DiscordComponents(self.bot) # Для когов
DiscordComponents(bot) # Без когов
- Вы ставили условие на проверку канала?
responce = await bot.wait_for('button_click')
if responce.channel == ctx.channel:
if responce.component.label == 'Да':
await responce.respond(content = 'Деньги успешно переведены!')
elif responce.component.label == 'Нет':
await responce.respond(content = 'Вы отменили перевод.')
Я исправил в 5-й строке моего мини-кода else на elif
.