Share your repls and programming experiences

← Back to all posts
Discord Buttons - A library for creating reaction buttons easily in discord.py.
h
xfinnbar

DiscordButtons

DiscordButtons is an extension to the discordpy framework that allows you to create cool reaction buttons more easily.

Before click:

After click:

Normally, writing this would be annoying. In the example below, I use DBtns to make the process a lot simpler.

Creating a new bot with DiscordButtons

Fork the template at the bottom of this page to get started. It's easy!

Adding DiscordButtons to an existing discordpy bot

To add discordbuttons to an existing bot, go to the template at the bottom of the page. Click on "files" and select discordbuttons.py and copy all the code inside it. Then, go to your repl or a local bot and create a file named discordbuttons.py, then paste all the code you copied earlier in there. Finally, add from discordbuttons import DBtns. You now have access to all the features of DiscordButtons.

Note: I plan to upload this package to PyPi soon, but I will not do it yet.

Documentation

class DBtns (extends commands.Cog)

You are meant to use this class as a cog.

  • __init__(bot, message, user = None, clear_buttons = True)

    • bot: Your commands.Bot or discord.Client instance. Usually client or bot.
    • user: The person that sent the command or triggered the buttons to appear. This user will be passed into events.
    • clear_buttons: Whether or not to remove all the reactions after the button has been clicked.
  • async add_button(emoji = '✅', on_click = print_hello_world, data = {}):

    • emoji: The emoji to add as a reaction.
    • on_click: Function to be called when the button is clicked. Arguments are passed:
      • message: Message that the button was created on.
      • user: User who clicked the button.
      • allowed_user: User who created the button (passed to __init__).
      • data: Data passed to add_button.
Voters
21ksnowy
LovelyBush
jort57
JosueHernandes
programmeruser
cuber1515
xfinnbar
Comments
hotnewtop
cuber1515

Cool! I bookmarked this for whenever I start back on my discord bot.

jort57

Amazing!