Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   2716

Discord.py Buttons explanation

by Slugy - 02 June, 2021 - 06:20 PM
This post is by a banned member (Slugy) - Unhide
Slugy  
Registered
11
Posts
3
Threads
4 Years of service
#1
(This post was last modified: 13 June, 2021 - 04:58 PM by Slugy. Edit Reason: Fixed code, new discord )
Discordcomponents Buttons
Discord.py
The Buttons in Discord.py are not added to the Docs so some 3rd party Docs have them included but not very good explained so i will try to make things easier for you
 
  • How to Download: 
    pip install --upgrade discord-components or py -version -m pip install buttons
  • Import: from discord_components import Button, ButtonStyle, InteractionType
  • Example Code:
 
Code:
import discord
from discord.ext import commands
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType

intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", intents=intents)

@bot.event
async def on_ready():
    print(f"{bot.user.name} is ready.")
    DiscordComponents(bot)


@bot.command()
async def test(ctx):
    await ctx.send(
        "Discord Buttons test",
        components=[
                [   # this Bracket is here, because else the Buttons would be among themselves and not side by side, so every row has like 5 or 6 places and then u would need to start a new row
                Button(style=ButtonStyle.blue, label="Blue",),
                Button(style=ButtonStyle.green, label="Green"),
                Button(style=ButtonStyle.gray, label="Gray"),
                Button(style=ButtonStyle.red, label="Red"),
                Button(style=ButtonStyle.grey, label="Grey"),
                ],
                [
                Button(style=ButtonStyle.grey, label="Emoji", emoji="?"),    # only standart emojis are possible
                Button(style=ButtonStyle.URL, label="url", url="https://cracked.sh/Slugy"),
                Button(style=ButtonStyle.red, label="Disabled", disabled=True)
                ]
            ],
        )
    y = await ctx.bot.wait_for("button_click")
    await y.respond(type=InteractionType.ChannelMessageWithSource,
        content=f'{y.component.label} clicked by {y.user}')

bot.run("") # your token

This is the simpliest way to explain it. In this code, for example i already did a Ticket System with it, that was much harder than this. The Button can be clicked just once. If u want, that the button can be clicked muliple times, put it in a loop where the message gets send over and over again or edit the message everytime with the new buttons also in a loop. You could also put the await ctx.bot.wait_for("button_click") in a complete own listener so your code looks cleaner!

If you need any Help/hace some questions feel free to DM me on Discord : Slug#8888

I hope i was able to help you. You can also check out my Profile, soon more Discord.py things!  pepeblush
This post is by a banned member (Lejonjon) - Unhide
This post is by a banned member (Kopiko777) - Unhide
Kopiko777  
Registered
6
Posts
1
Threads
4 Years of service
#3
Kys sluggy69, code bot for me rn
This post is by a banned member (Lejonjon) - Unhide
This post is by a banned member (BreezyHQ) - Unhide
BreezyHQ  
Registered
174
Posts
50
Threads
5 Years of service
#5
plox fren
[Image: 06c6539fb68d5ffefb6f974ab150239a]
This post is by a banned member (Slugy) - Unhide
Slugy  
Registered
11
Posts
3
Threads
4 Years of service
#6
This is a bump
This post is by a banned member (zxrby) - Unhide
zxrby  
Registered
26
Posts
0
Threads
4 Years of service
#7
(02 June, 2021 - 06:20 PM)Slugy Wrote: Show More
Discordcomponents Buttons
Discord.py
The Buttons in Discord.py are not added to the Docs so some 3rd party Docs have them included but not very good explained so i will try to make things easier for you
 
  • How to Download: 
    pip install --upgrade discord-components or py -version -m pip install buttons
  • Import: from discord_components import Button, ButtonStyle, InteractionType
  • Example Code:
 
Code:
import discord
from discord.ext import commands
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType

intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", intents=intents)

@bot.event
async def on_ready():
    print(f"{bot.user.name} is ready.")
    DiscordComponents(bot)


@bot.command()
async def test(ctx):
    await ctx.send(
        "Discord Buttons test",
        components=[
                [   # this Bracket is here, because else the Buttons would be among themselves and not side by side, so every row has like 5 or 6 places and then u would need to start a new row
                Button(style=ButtonStyle.blue, label="Blue",),
                Button(style=ButtonStyle.green, label="Green"),
                Button(style=ButtonStyle.gray, label="Gray"),
                Button(style=ButtonStyle.red, label="Red"),
                Button(style=ButtonStyle.grey, label="Grey"),
                ],
                [
                Button(style=ButtonStyle.grey, label="Emoji", emoji="?"),    # only standart emojis are possible
                Button(style=ButtonStyle.URL, label="url", url="https://cracked.sh/Slugy"),
                Button(style=ButtonStyle.red, label="Disabled", disabled=True)
                ]
            ],
        )
    y = await ctx.bot.wait_for("button_click")
    await y.respond(type=InteractionType.ChannelMessageWithSource,
        content=f'{y.component.label} clicked by {y.user}')

bot.run("") # your token

This is the simpliest way to explain it. In this code, for example i already did a Ticket System with it, that was much harder than this. The Button can be clicked just once. If u want, that the button can be clicked muliple times, put it in a loop where the message gets send over and over again or edit the message everytime with the new buttons also in a loop. You could also put the await ctx.bot.wait_for("button_click") in a complete own listener so your code looks cleaner!

If you need any Help/hace some questions feel free to DM me on Discord : Slug#8888

I hope i was able to help you. You can also check out my Profile, soon more Discord.py things!  pepeblush

+rep nigger the best men of the world
This post is by a banned member (Slugy) - Unhide
Slugy  
Registered
11
Posts
3
Threads
4 Years of service
#8
This is a bump

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)