All you need to know about Buttons in Discord.py & Pycord | Ultimate Python Guide

  Рет қаралды 128,733

Code With Swastik

Code With Swastik

Күн бұрын

This is the Ultimate Python Guide on Buttons with Discord.py or Pycord. In this video, I talk about how to create buttons in discord.py or pycord and how to respond to button clicks along with everything about Views. After watching this you'll know everything about Buttons and Views in discord.py or pycord.
This video might also apply to other discord.py forks like Nextcord Enhanced discord.py or disnake as they have been forked from discord.py 2.0.
If you have any suggestions for future videos/doubts, leave it in the comments below. I might not be able to answer everyone but you can join my discord server for help: / discord
▬▬▬▬ Install Pycord or Discord.py ▬▬▬▬
Pycord: pip install -U git+github.com/Pycord-Development...
discord.py: pip install -U git+github.com/Rapptz/discord.py
▬▬▬▬ Links Referenced in this Video ▬▬▬▬
Pycord Server - / discord
Pycord Github - github.com/Pycord-Development...
Pycord Docs: docs.pycord.dev
Discord.py Github: github.com/Rapptz/discord.py
Discord.py Docs: discordpy.readthedocs.io/en/m...
▬▬▬▬ My Socials ▬▬▬▬
My Discord - / discord
My Twitter - / codewithswastik
My Instagram - / code_with_swastik
▬▬▬▬ Contents of this video ▬▬▬▬
0:00 - Intro
0:12 - Requirements
1:00 - Taking a look at buttons
1:27 - Creating buttons
10:58 - Responding to button clicks
15:57 - Subclassing discord.ui.Button
18:31 - Subclassing discord.ui.View
20:33 - Editing buttons
24:37 - View Timeouts and on_timeout
26:15 - View error handling and on_error
27:17 - More on Views
30:10 - View interaction_check
31:37 - Button positions and Button.row
34:12 - Outro
▬▬▬▬ Queries solved in the video: ▬▬▬▬
1) How to use buttons with discord.py 2.0 and its forks
2) Create buttons with pycord or discord.py
3) Guide on message components with discord.py or pycord
4) How to create discord buttons in Python
5) How to respond to button clicks in Pycord/Discord.py
#pycord #discord #buttons

Пікірлер: 200
@TheMorphium
@TheMorphium Жыл бұрын
This was an exceptionally helpful video. Especially as you got in to the object oriented aspects at the end. Answered precisely what I was looking to find out. And I was able to apply these concepts to Modal's as well, so bonus.
@jimlo
@jimlo 2 жыл бұрын
This is a very helpful video for getting an intro to buttons. Thanks for posting it! Gonna try and incorporate some buttons into my Discord bot thanks to you :D
@stevenmao6766
@stevenmao6766 2 жыл бұрын
Unironically covered everything I needed to know, love the video and thanks
@martinb.8912
@martinb.8912 2 жыл бұрын
Nice video! Very good information about buttons. Highly recommended
@mochy1
@mochy1 2 жыл бұрын
Thank you, this is really helpful! I had to use interactions.response.message.edit instead of interactions.response.edit_message because the module was updated.
@dprk
@dprk 2 жыл бұрын
Wow! i was hesitant to migrating to buttons but now i've watched this amazing explanation, i will defs switch, subbed
@CodeWithSwastik
@CodeWithSwastik 2 жыл бұрын
Awesome, thank you!
@ayva1106
@ayva1106 2 жыл бұрын
Helpful. To the point and informative. Thank you for the awesome video 👍🏽
@basedneutral1173
@basedneutral1173 5 ай бұрын
haram pfp you're a dude 🤣
@LurkzGaming
@LurkzGaming Жыл бұрын
Great video you explained it very well. Thanks!
@rafid_zx
@rafid_zx 2 жыл бұрын
Thanks a lot. Your videos are great!
@patio6473
@patio6473 2 жыл бұрын
Please make a tutorial on how to do a reaction role that has, for example, bot carlbot. I think it would be useful🙂
@patio6473
@patio6473 2 жыл бұрын
Thank you to everyone who liked the comment♥ If there are more likes, maybe we will motivate Code With Swastik more to record the guide😃
@willyrire
@willyrire Жыл бұрын
@@patio6473 I can send you a working code i made for role reaction if you want
@SouProds
@SouProds 2 жыл бұрын
Tysm! This worked for me.
@arnavupadhyay4089
@arnavupadhyay4089 2 жыл бұрын
Ayy tysm for this!
@AK1770
@AK1770 2 жыл бұрын
thank you so much i needed this
@insightos3424
@insightos3424 2 жыл бұрын
Excellent Video!
@ronykax
@ronykax Жыл бұрын
Hey Swastik, great video as always. I have a teany tiny problem with my code, so basically I have made a button in a view class and awaited the view class upon the on_ready function but the button doesn't show up and has no errors either.
@kitts1888
@kitts1888 11 ай бұрын
Thank you !! you are the best i stuck with discord button i think 6-7 hour.
@eee479
@eee479 2 жыл бұрын
great video, how do you set the label of the button when its initialized in a view subclass though
@TirthTheDev
@TirthTheDev 2 жыл бұрын
Amazing First time works
@SlimeyDev
@SlimeyDev 2 жыл бұрын
I LOVE UR CONTENT!!!!!!
@ethanonysko
@ethanonysko 2 жыл бұрын
How do you make these combatable with slash commands? edit: figured out I was using a third party package for slash commands
@parsec3984
@parsec3984 2 жыл бұрын
thank you, very helpful
@ShomShom37
@ShomShom37 2 ай бұрын
you saved me, thx so much!
@limjunyu9672
@limjunyu9672 2 жыл бұрын
damn finally someone with the official buttons
@Zaeemtechnical
@Zaeemtechnical 2 жыл бұрын
please make a video on select menu and i loved you're video very much it was very informative...
@BWP09
@BWP09 10 ай бұрын
very helpful video!
@EnokiUN
@EnokiUN 2 жыл бұрын
Nice stuff.
@MS-fp5jq
@MS-fp5jq Жыл бұрын
do you have any examples of interacting with discord buttons without building bot? for example, connecting via a user authorization token (instead of a bot token)?
@leonardogenzano1939
@leonardogenzano1939 Жыл бұрын
great video! In a view, is it possible to edit a link button that was instanciated from another class. I did it that way because the library says this: (Buttons with a URL cannot be created with this function.Consider creating a :class:`Button` manually instead.) The problem with this approach is that I can't understand how to define the callback for that button that was added from another class (for example, I want to edit it so its disabled after clicking it).
@Selfik_Gamer
@Selfik_Gamer Жыл бұрын
Thanks you very much! i'm looking for it very long time.... i realy tired...
@cjack3635
@cjack3635 2 жыл бұрын
i did this with my music bot and it worked=))
@vision6568
@vision6568 2 жыл бұрын
hey , in 25:49 , how to make buttons disabled or remove them during timeout? no interaction parameter so how to edit the old msg?
@shryansh_a16
@shryansh_a16 2 жыл бұрын
I need a help! I want to mention the author of the message who triggered the buttons. How to add this in embed of edited message in button class
@seyedmahdimoosavian805
@seyedmahdimoosavian805 2 жыл бұрын
nice! please make a video about Select buttons
@simon62821
@simon62821 Жыл бұрын
thanks for this!!
@aqumy
@aqumy 2 жыл бұрын
you need to make a pycord tutorial series haha
@nixonxc7157
@nixonxc7157 2 жыл бұрын
Really hepful!
@gilad7964
@gilad7964 Жыл бұрын
im doing a voting system with the buttons how can i do that for a member when he press a second time it will change the message and if press a 3rd time it will go back to the original
@ccode8194
@ccode8194 Жыл бұрын
Thank you!😄👍
@alex59292
@alex59292 Жыл бұрын
I wanted to edit button to be disabled and this helped thanks
@yoavits4100
@yoavits4100 Жыл бұрын
Question, how do you make a url button with the @discord.ui.button? because i don't have such argument.
@zaaffe24bs16
@zaaffe24bs16 2 жыл бұрын
How do I change the style when clicking
@GamerUA_MV
@GamerUA_MV 5 ай бұрын
Thanks, man, you really helped me understand how it works. Otherwise, my head was already boiling.
@Ishir123
@Ishir123 2 жыл бұрын
Hi , can you pls confirm how to import ButtonStyle
@TEKNOTIPS
@TEKNOTIPS Жыл бұрын
best loved it
@user-ti7rs9ss5i
@user-ti7rs9ss5i 5 ай бұрын
But how do you add functionality to the buttons added by the loop?? Since they're just empty templates
@PropertyMos
@PropertyMos Жыл бұрын
self.ctx.send() doesn't work for me on the latest discord py. What can we do here instead?
@excalizan7697
@excalizan7697 2 жыл бұрын
Thanks for the great tutorial dude! I wonder what VSCode theme are you using? Thanks!
@flicko0
@flicko0 2 жыл бұрын
ayu maybe
@Savedon-131
@Savedon-131 Жыл бұрын
The interaction_response can't be imported and is not identified. Please help, thanks!
@graeysheep
@graeysheep 2 жыл бұрын
Can you make a video for select menus? Nice Video
@rebootsociety7675
@rebootsociety7675 2 жыл бұрын
I can't able to use buttons even I installed but there is no error in console and not even showing anything when I using command Pls help me asap.
@chap2837
@chap2837 Жыл бұрын
swastik i need help please when i do the from discord.ui import Button command it says that discord.ui doesnt exist
@pyxcoding
@pyxcoding 2 жыл бұрын
How to fix the unknown interaction error?it's getting to me and it's soo annoying. I deferred the action too. Pls help
@something6034
@something6034 Жыл бұрын
What is the plugin you use for this beautyfull vscode? Edit: I found it: code blue
@benzene0606
@benzene0606 2 жыл бұрын
hmm... how to add drop down menu in help command using buttons ?
@MrGidorMr
@MrGidorMr Жыл бұрын
Hey do you know how can i call another command with a button?
@ashutosh9901
@ashutosh9901 2 жыл бұрын
module not found i tried exactly same like u but it shows error
@Jimrim
@Jimrim 2 жыл бұрын
i installed the modules but get an error called module not found i tried to reinstall etc but npthing worked can some1 pls help me
@RasFace
@RasFace Жыл бұрын
I'm sorry that the question is off topic... What is the name of your theme in VS Code?
@user-uf5cj5cb1e
@user-uf5cj5cb1e Жыл бұрын
the end of The video teach me how to use for loops to create buttons , but how can I get feedback on those buttons?
@reflex7649
@reflex7649 2 жыл бұрын
what keyboard do you use ?
@vins1769
@vins1769 10 ай бұрын
may I ask how to add a button to a message after clicking a button?
@ejmanuel6024
@ejmanuel6024 2 жыл бұрын
Why when ever I start the bot it says "No module named discord.ui"?
@HaxDX
@HaxDX Жыл бұрын
How can I make it so the buttons only respond to the person who used the command?
@CodeBinge
@CodeBinge 2 жыл бұрын
Thanks!
@GlobalSpotlight
@GlobalSpotlight 2 ай бұрын
How can I generate more button by click a single button?
@IdiotWrangler
@IdiotWrangler Жыл бұрын
25:26 for anyone looking to where he passed the ctx of the message into the View, was scouring the web for this.
@giovancsihombing
@giovancsihombing 2 жыл бұрын
Do you have your repostory published?
@starkavenger246
@starkavenger246 2 жыл бұрын
wait which part of the video talks about pycord?
@thepladiatoregaming5205
@thepladiatoregaming5205 2 жыл бұрын
I'm having a problem with the View command in PyCord
@Untergrund_Koenig
@Untergrund_Koenig 3 ай бұрын
Can you show us how we can use the buttons and selects permanently? Because if the bot reconnects, the buttons and selects are no longer functional :(
@technicalsupportandvids4298
@technicalsupportandvids4298 2 жыл бұрын
bro it says that discord.ui not found please help me
@minhminer
@minhminer 2 жыл бұрын
great video, i found this really helpful, but I'm still wondering how to disable all buttons inside the on_timeout() function, thanks a a lot for your help
@CodeWithSwastik
@CodeWithSwastik 2 жыл бұрын
Just loop through all the view.children and set item.disabled=True. Don't forget to edit the message though!
@minhminer
@minhminer 2 жыл бұрын
@@CodeWithSwastik but how can I get that message object, self.message?
@blitzwolf336
@blitzwolf336 2 жыл бұрын
@@minhminer interaction.response.edit_message(view=self)
@krishnans2006
@krishnans2006 2 жыл бұрын
I had the same question - the "on_timeout()" function doesn't have an interaction parameter, so you can access and disable the buttons alright, but how would you edit the message without the interaction object?
@ar_maan05
@ar_maan05 2 жыл бұрын
@@CodeWithSwastik hi, can you please explain how to do it?
@GlobalSpotlight
@GlobalSpotlight 2 ай бұрын
Is a Channel in Discord private? If so how can I make it private for every user?
@thememesbox
@thememesbox 2 жыл бұрын
Danny says All dpy fork are bad. Why?
@AK1770
@AK1770 2 жыл бұрын
can you do the dropdown menu list thing next?
@ThemeParkDanUK
@ThemeParkDanUK 2 жыл бұрын
Please make a new video on how to make a calculator using the pycord buttons!
@xerro_bog
@xerro_bog Жыл бұрын
you're awesome
@stellar4677
@stellar4677 2 жыл бұрын
How do you pass an argument into a button callback?
@muralieb
@muralieb 2 жыл бұрын
It says discord.ui module not found error
@PretzelGangx
@PretzelGangx 11 ай бұрын
why my bot doesnt sending errors and doesnt sending the message with button
@amberblade3722
@amberblade3722 2 жыл бұрын
I installed pycord but discord.ui isnt importing
@thomascat4872
@thomascat4872 2 жыл бұрын
You should make a video on Select menus
@Pawlo370
@Pawlo370 2 ай бұрын
how to make bot like mudae?
@badonker
@badonker 2 жыл бұрын
useful, but the subclass part literally don't work in cogs
@devshah8058
@devshah8058 2 жыл бұрын
please get a software for noise cancellation, the keyboard sound is really annoying
@soze2440
@soze2440 2 жыл бұрын
is there a way to restrict the buttons for author without subclassing buttons?
@willyrire
@willyrire Жыл бұрын
i think yes if you add the author id in the button id
@FlockersDesign
@FlockersDesign 2 жыл бұрын
This doenst seem to work anymore
@DylnCox
@DylnCox 2 жыл бұрын
How about a tutorial on how to send DMs when button is pressed?
@rahulboligarla8540
@rahulboligarla8540 2 жыл бұрын
Can anyone tell my how do i make my bot interact with buttons which are provided by other bots ?
@yairkaz
@yairkaz 2 жыл бұрын
You cannot
@frozn14
@frozn14 2 жыл бұрын
What VSC theme do you use?
@excalizan7697
@excalizan7697 2 жыл бұрын
I was wondering that too...
@yxshv
@yxshv 2 жыл бұрын
how to change the label or disable the button without subclassing the view
@pyxcoding
@pyxcoding 2 жыл бұрын
button = Button(label="your new label") button.disabled = True view.add_item(button) await interaction.response.edit_message(view=view)
@Milk-yi9hg
@Milk-yi9hg 2 жыл бұрын
On the line 'from discord.ui import Button' I got this error 'Import "discord.ui" could not be resolved'
@skilly-9865
@skilly-9865 2 жыл бұрын
use "from discord_ui import Button"
@nightmanmain4858
@nightmanmain4858 2 жыл бұрын
I can't import View
@unitytechnical7367
@unitytechnical7367 2 жыл бұрын
Its Saying module not found discord.ui
@ADITYAKUMAR-jv9yy
@ADITYAKUMAR-jv9yy 2 жыл бұрын
sir i am getting a error that send() got an unexpected keyword argument 'view'
@limjunyu9672
@limjunyu9672 2 жыл бұрын
you definitely have the "discord_components" package, you need to delete it as its breaking the beta version of dpy
@ADITYAKUMAR-jv9yy
@ADITYAKUMAR-jv9yy 2 жыл бұрын
@@limjunyu9672 it worked bro thanks !
@zaaffe24bs16
@zaaffe24bs16 2 жыл бұрын
Is there a way to simply disable the buttons in a normal command without class and stuff? Idk if I just missed it can someone maybe send timestamp or solution
@soosplays2306
@soosplays2306 2 жыл бұрын
button.disabled = True
@zaaffe24bs16
@zaaffe24bs16 2 жыл бұрын
@@soosplays2306 I tried that but nothing happens
@MarkoKupresanin
@MarkoKupresanin 2 жыл бұрын
@@zaaffe24bs16 You need to do await interaction.response.edit_message(view=self) as well
@zaaffe24bs16
@zaaffe24bs16 2 жыл бұрын
@@MarkoKupresanin umm isn’t self only for classes and cogs
@wilcuber6376
@wilcuber6376 2 жыл бұрын
disabled is a parameter inside the button. so if you do discord.ui.Button(disabled=True) the button is disabled. You can also add the other things like style or emoji
@abdooowd
@abdooowd 2 жыл бұрын
when i run my code i get an error saying Traceback (most recent call last): File "main.py", line 3, in from discord.ui import Button, View ModuleNotFoundError: No module named 'discord.ui'
@wilcuber6376
@wilcuber6376 2 жыл бұрын
update pycord in your terminal with "pip install py-cord==2.0.0b1"
@shayankermani8431
@shayankermani8431 2 жыл бұрын
@@wilcuber6376 WOW! helped me a lot tnx :)
@tuncay7061
@tuncay7061 2 жыл бұрын
@@wilcuber6376 thanks bud you saved me
@DoubleF3lix
@DoubleF3lix 2 жыл бұрын
Is it possible to send a button by itself?
@randomguy34919
@randomguy34919 2 жыл бұрын
Yep, just make the bot send like this: await ctx.send('_ _', view=view) This makes an invisible message except for the components
@skyletwings5711
@skyletwings5711 2 жыл бұрын
I get the error message that the commands.Bot constructor call needs the mandatory keyword argument 'intents' now. I followed your instructions, especially the install of pychord and discord.py. But I assume that this is a new feature that I automatically pulled from github. However, all my tries to define a default intent just lead to further and further constructor errors. My question: Is there an updated version of this phenomenal video, telling how to cope with the new intents? Either deactivate or correctly implement them? I would appreciate anyone's constructive feedback, thank you!
@rockoyhead
@rockoyhead 2 жыл бұрын
sigh one of us
@skyletwings5711
@skyletwings5711 2 жыл бұрын
@@rockoyhead I'm sorry, what do you mean?
@rockoyhead
@rockoyhead 2 жыл бұрын
make this variable intents = discord.Intents().all() now pass in bot = commands.Bot(command_prefix=">", intents=intents)
@skyletwings5711
@skyletwings5711 2 жыл бұрын
@@rockoyhead Thank you, I'll try
Discord PAGINATION: All You Need to Know
10:38
Richard Schwabe
Рет қаралды 12 М.
Best KFC Homemade For My Son #cooking #shorts
00:58
BANKII
Рет қаралды 63 МЛН
Самый Молодой Актёр Без Оскара 😂
00:13
Глеб Рандалайнен
Рет қаралды 12 МЛН
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 39 МЛН
Бот для сервера Discord на Python
57:01
Фсоки
Рет қаралды 122 М.
Python/Pygame Minesweeper Tutorial
48:41
Daniel Chang
Рет қаралды 28 М.
Learn .NET MAUI - Full Course for Beginners | Build cross-platform apps in C#
4:08:53
Make a Discord Bot with Slash Commands
11:07
Ethan | The Code Syndicate
Рет қаралды 3 М.
low battery 🪫
0:10
dednahype
Рет қаралды 573 М.
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18
Что делать если в телефон попала вода?
0:17
Лена Тропоцел
Рет қаралды 2,8 МЛН
НОВЫЕ ФЕЙК iPHONE 🤯 #iphone
0:37
ALSER kz
Рет қаралды 270 М.
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 16 МЛН
Xiaomi SU-7 Max 2024 - Самый быстрый мобильник
32:11
Клубный сервис
Рет қаралды 510 М.