Answer the question
In order to leave comments, you need to log in
How to work with discord buttons?
Hello, I’m making a discord bot, I recently stumbled upon the discord_components library and decided to use it to make the “help” command, but I don’t understand how to make a button click handler, I can’t throw everything into a bunch because the bot doesn’t understand this and gets confused, all the code below please help with the button click handler.
The code:
@commands.command()
@commands.has_permissions( administrator = True ) # Allowed only for server admins
async def help(self, ctx):
buttons1 = [
[
Button(label = "◀", disabled = True),
Button(style = ButtonStyle.red, label = "Cancel"),
Button(label = "▶")
],
]
buttons2 = [
[
Button(label = "◀"),
Button(style = ButtonStyle.red, label = "Cancel"),
Button(label = "▶")
],
]
buttons3 = [
[
Button(label = "◀"),
Button(style = ButtonStyle.red, label = "Cancel"),
Button(label = "▶", disabled = True)
],
]
emb1 = discord.Embed(title = 'Справочник по командам', description = """
Привет, спасибо что используешь меня на своем сервере! Для того чтобы просмотреть все команды модулей, переключай страницы кликая на реакции ниже.
\n\n **Все модули:**
⚙ **Основное**
**Модерация**
**Музыка**
ℹ **Информация**
**Логирование**
**Экономика**
**Мини-Игры**
**Ультилиты**
**Эмоции**
**Животные**
**NSFW**""", colour = 0xb370f1)
emb1.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb2 = discord.Embed(title = 'Основное', description = """
`!ping` - Скорость отклика бота.
`!report` - Связь с разработчиком бота.""", colour = 0xb370f1)
emb2.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb3 = discord.Embed(title = 'Модерация', description = """
`!kick` - Исключить пользователя.
`!ban` - Забанить пользователя.
`!massunban` - Массовая разблокировка.
`!mute` - Заглушить пользователя по всему серверу.
`!unmute` - Снять с участника мьют.
`!warn` - Выдать предупреждение.
`!remwarn` - Снять предупреждение.
`!warns` - Просмотреть предупреждения участника.
`!clear` - Очистить последние сообщения в текущем канале.""", colour = 0xb370f1)
emb3.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb4 = discord.Embed(title = 'Музыка', description = """-""")
emb4.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb5 = discord.Embed(title = 'Информация', description = """
`!user` - Информация о пользователе.
`!serverinfo` - Информация о сервере.""", colour = 0xb370f1)
emb5.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb6 = discord.Embed(title = 'Логирование', description = """-""", colour = 0xb370f1)
emb6.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb7 = discord.Embed(title = 'Экономика', description = """-""", colour = 0xb370f1)
emb7.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb8 = discord.Embed(title = 'Мини-Игры', description = """-""", colour = 0xb370f1)
emb8.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb9 = discord.Embed(title = 'Ультилиты', description = """
`!say` - Сказать от имени бота.
`!8ball` - Шар предсказаний.
`!incogm` - Отправить сообщение Инкогнито.
`!wiki` - Поиск статей в Wikipedia""", colour = 0xb370f1)
emb9.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb10 = discord.Embed(title = 'Эмоции', description = """
`!hug` - Обнимашки.
`!kiss` - Поцелуйчики.
`!bite` - Укусить.
`!sad` - Грустить.
`!cry` - Плакать.
`!love` - Признаться в любви.
`!pat` - Погладить.
`!poke` - Тыкнуть.
`!lick` - Облизать.
`!slap` - Пощечина.
`!hit` - Ударить.""", colour = 0xb370f1)
emb10.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb11 = discord.Embed(title = 'Животные', description = """
`!cat` - Фото милых кошечек.
`!dog` - Красивые, породистые собачки.
`!fox` - Лисички? Нет это не грибы.
`!panda` - Как панда кунфу, только круче.
`!koala` - Куалы, ну кто их не любит.
`!birb` - Странное название для птички.""", colour = 0xb370f1)
emb11.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
emb12 = discord.Embed(title = 'NSFW', description = """-""", colour = 0xb370f1)
emb12.set_thumbnail(url = "https://cdn.discordapp.com/avatars/823964850711429130/e16c56bcab589575a1eeee899f920443.webp?size=1024")
#embeds = [embed1, embed2, embed3, embed4, embed5, embed6, embed7, embed8, embed9, embed10, embed11, embed12]
await ctx.send(embed = emb1, components = buttons1)
res = await self.bot.wait_for("button_click", timeout = 20)
if res.component.label == 'Cancel':
await res.respond(type = 6)
await res.message.delete()
res2 = await self.bot.wait_for("button_click", timeout = 20)
if res2.component.label == '▶':
await res2.respond(type = 6)
await res2.message.edit(embed = emb2, components = buttons2)
res3 = await self.bot.wait_for("button_click", timeout = 20)
if res3.component.label == '◀':
await res3.respond(type = 6)
await res2.message.edit(embed = emb1, components = buttons2)
res4 = await self.bot.wait_for("button_click", timeout = 20)
if res4.component.label == 'Cancel':
await res4.respond(type = 6)
await res4.message.delete()
res5 = await self.bot.wait_for("button_click", timeout = 20)
if res5.component.label == '▶':
await res5.respond(type = 6)
await res5.message.edit(embed = emb2, components = buttons2)
<code>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question