Advertisement
Fsoky

Discord Buttons | DiscordComponents

Feb 28th, 2022
2,659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3.  
  4. from discord_components import DiscordComponents, Button, ButtonStyle
  5.  
  6. bot = commands.Bot(command_prefix=".", intents=discord.Intents.all())
  7.  
  8.  
  9. @bot.event
  10. async def on_ready():
  11.     DiscordComponents(bot)
  12.  
  13.  
  14. @bot.command()
  15. async def test(ctx):
  16.     await ctx.send(embed=discord.Embed(title="Invite to party"),
  17.         components=[
  18.             [
  19.                 Button(style=ButtonStyle.green, label="Accept", emoji="πŸ₯‘"),
  20.                 Button(style=ButtonStyle.red, label="Decline", emoji="🌹"),
  21.                 Button(style=ButtonStyle.red, label="I'll think...", emoji="πŸ€”")
  22.             ],
  23.             [
  24.                 Button(style=ButtonStyle.URL, url="https://youtube.com/c/Ѐсоки", label="YouTube")
  25.             ]
  26.         ]
  27.     )
  28.  
  29.     response = await bot.wait_for("button_click")
  30.     if response.channel == ctx.channel:
  31.         if response.component.label == "Accept":
  32.             await response.respond(content="Great! πŸ₯°")
  33.         else:
  34.             await response.respond(embed=discord.Embed(title="Are you sure?"),
  35.                 components=[
  36.                     [
  37.                         Button(style=ButtonStyle.green, label="YES"),
  38.                         Button(style=ButtonStyle.red, label="NO")
  39.                     ]
  40.                 ]
  41.             )
  42.  
  43.  
  44. bot.run("TOKEN")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement