How to Make a Discord Bot with Python

  Рет қаралды 55,706

pixegami

pixegami

Күн бұрын

Learn how you can create your own simple Python Discord bot in this tutorial! Your bot will be able to respond to commands like "!hello" and "!add 4 5 6". We'll also make the bot able to help us study/work by tracking our focus sessions, and reminding us when to take a break (on a scheduled timer).
🛠 Code:
github.com/pixegami/simple-di...
🔗 Discord Developer Portal: / discord
🔗 discord.py: github.com/Rapptz/discord.py
🔗 Documentation: discordpy.readthedocs.io/en/s...
📽 Chapters
00:00 Introduction: What you will build
02:52 Setting up the Discord bot
09:15 Saying "Hello World!"
13:25 Responding to user commands
14:49 Commands with arguments - add(x, y)
17:01 Starting a "study" session
19:22 Ending a "study" session
20:48 Creating a scheduled task
25:28 Recap and wrap-up
#pixegami #python

Пікірлер: 102
@zzz-oc4fe
@zzz-oc4fe Жыл бұрын
Just found your channel. Watched the AI SaaS video and am now on the portfolio site for beginners. The level of detail you put into explaining things in your videos is just right. Please keep making content, thanks a lot.
@pixegami
@pixegami Жыл бұрын
😅 Thanks for your kind works. It is a challenge for me to balance the content to be fast and simple, but still comprehensive enough to learn from, so hearing that it works for you is very encouraging!
@rachit.6110
@rachit.6110 Жыл бұрын
@@pixegami you're a great teacher please continue this course
@akuan195
@akuan195 Жыл бұрын
you are awesome, this is the only one tutorial that works for me
@pixegami
@pixegami Жыл бұрын
Glad to hear that!
@ArunWills7
@ArunWills7 Жыл бұрын
the only tutorial that actually works, thanks a ton!
@pixegami
@pixegami Жыл бұрын
Glad it helped!
@SIMP_Toast87
@SIMP_Toast87 Жыл бұрын
Best tutorial!❤
@kingking7698
@kingking7698 Жыл бұрын
Thank you for the awesome video!!
@pixegami
@pixegami Жыл бұрын
You're welcome!
@AudreyGraceB
@AudreyGraceB 5 ай бұрын
Great tutorial! Thanks a lot!
@pixegami
@pixegami 5 ай бұрын
You're welcome!
@homerovignecarpi8913
@homerovignecarpi8913 4 ай бұрын
THANKS A LOT MAN, YOU WERE OF GREAT HELP!!!!
@pixegami
@pixegami 4 ай бұрын
You're welcome!
@B1oodbeard
@B1oodbeard 5 ай бұрын
This helped so much to get started
@pixegami
@pixegami 5 ай бұрын
Glad to hear it. Thank you!
@katerinejaimes6585
@katerinejaimes6585 8 ай бұрын
Justo lo que necesitaba, me gusta como explica todo mjuy bien, aunque es en ingles es un reto tambien porque estoy aprendiendo asi que es un Plus. Muchas gracias. Una suscriptora mas 😊
@pixegami
@pixegami 8 ай бұрын
Thank you! I'm glad you enjoyed it. I hope you were able to understand the video :)
@Filaskon
@Filaskon 4 ай бұрын
So helpful :D this tutorial is perfect bc i need a bot that runs a command every 24 hrs bc im lazy lol
@solo_zither6365
@solo_zither6365 Жыл бұрын
you are a god
@nileshswami2426
@nileshswami2426 Жыл бұрын
Thank you🤩
@pixegami
@pixegami Жыл бұрын
You’re welcome 😊
@Daraca5
@Daraca5 7 ай бұрын
Thank you! this was great, half the battle with things like this is getting the thing to run to begin with, so you've gotten me that far, much better tutorial than all the rest I've come across.
@pixegami
@pixegami 7 ай бұрын
Awesome! Glad to hear it was useful :)
@jason6569
@jason6569 5 ай бұрын
This was exactly what I needed. Got it running in 10 minutes and coded what I needed. My one issue, and I know it isn't part of this is how to limit the bot to one channel! I did start it as administrator to test. Removed it and readded it with just manage and send messages in text permissions. Google is not helping and I am stumped. I don't want everyone to use my / commands! Just a specific channel. Again great tutorial, it did what it was supposed to! Thank you!
@pixegami
@pixegami 5 ай бұрын
Thank you! To solve your problem, here is one solution I found online: > The easiest way to do this is not actually via code but via permissions on the server. On your server you should find a role with the same name as your bot, whose permissions (including send messages) you can change for seperate channels. Otherwise, I guess you can do it hackily as well by using an if/else statement in the bot logic itself to only respond if the channel ID of the message is the one you want the bot to operate in.
@LavinOficial
@LavinOficial Ай бұрын
great video, direct and precise, I just want to ask you what happens if I want to give each user an ID, what would the logic be?
@Maple38
@Maple38 Жыл бұрын
Great tutorial. I looked through a lot of them, and while they worked, none of them really explained why they did stuff. They just wrote code and expected to follow.
@pixegami
@pixegami Жыл бұрын
Thanks for that feedback! It's something I actively try to achieve in my tutorials, so I'm glad it's coming across.
@openup8708
@openup8708 Ай бұрын
hey great video. i have a question. If I have code written already, how do I implement that code to work with the discord bot? For example, if I have a script written to return output for a certain input, how do I implement this to the discord bot so that if i place an input to the discord channel, it will output the values (from my script I created)
@retrokjay997
@retrokjay997 9 ай бұрын
do you know how to get the prizepick projections?
@theOtherGuy2175
@theOtherGuy2175 Жыл бұрын
Is there a way to have a catch all async def? Like if someone types /bot
@pixegami
@pixegami Жыл бұрын
No idea! I looked it up and found this: @bot.event async def on_command_error(ctx, error): await ctx.send(f"An error occured: {str(error)}") From stackoverflow.com/questions/62771154/discord-py-rewrite-sending-an-error-message-when-there-is-an-unknown-command-or
@gavinosegura4865
@gavinosegura4865 Жыл бұрын
i copied text by text to just have the bot print hello on the discord and i keep running into issues with on ready await channel.send Attribute error with python. Any suggestions?
@pixegami
@pixegami Жыл бұрын
Hmm, I checked the code recently and it was still working. What is the exact error and what version of discord.py are you using?
@rachit.6110
@rachit.6110 Жыл бұрын
Please continue this cource! Also please tell us everything from Discord api documentation and all of the bot commands available there please.
@MindUnearthed
@MindUnearthed 9 ай бұрын
when I want to install the 'pip install discord.py' error comes in and it says "which is required to install pyproject.toml-based projects" how do I make it install ?
@Dark-a242
@Dark-a242 8 ай бұрын
Exactly
@marcoshocpfner9184
@marcoshocpfner9184 Жыл бұрын
Thank for this... very useful, do you have enything about on discord bot whit cli AWC ?
@pixegami
@pixegami Жыл бұрын
Not at the moment, but I plan to do more Discord videos in the future.
@heckor8128
@heckor8128 Жыл бұрын
why does it show me [Done] exited with code=0 in 0.092 seconds after i do client.run(token) instead of showing my bot online
@joao_silva679
@joao_silva679 Жыл бұрын
If you did exactly as he did, you should use bot.run(token) instead of client.
@78wesley67
@78wesley67 Жыл бұрын
Which add-on do you use for auto generating code?
@pixegami
@pixegami Жыл бұрын
GitHub Copilot. I actually talk about it in this video: kzfaq.info/get/bejne/qq1og7Ofyp3JlmQ.html
@Alw1130
@Alw1130 11 ай бұрын
When I start a study session, the time is 5 hours later than intended. What is the fix for that?
@pixegami
@pixegami 11 ай бұрын
It probably uses the UTC time from the machine your bot is running on. What’s the timezone set on your system? You might have to set it to local time.
@spooky-
@spooky- 11 ай бұрын
my bot wont come online, ive check my code and token multipul times (im on mac)
@pixegami
@pixegami 11 ай бұрын
What error do you see?
@juliodiaz9093
@juliodiaz9093 Жыл бұрын
im trying this tutorial but when i ise the command, theres no response. the async function doesnt even run.
@pixegami
@pixegami Жыл бұрын
It's possible that the Discord package may have changed or been updated since the video was made :(
@ConsCrafter
@ConsCrafter 27 күн бұрын
which IDE is he using ?
@AloneNinja36
@AloneNinja36 11 ай бұрын
How can I make my Discord bot only appear in one channel and not work in other channels?
@pixegami
@pixegami 11 ай бұрын
You can add a condition into the functions so it only does things in a specific channel: "if message.channel.id == YOUR_CHANNEL_ID: ..."
@davudhaci5379
@davudhaci5379 Жыл бұрын
Which exintension are u use for complate code
@pixegami
@pixegami Жыл бұрын
GitHub CoPilot
@Manciek_
@Manciek_ 10 ай бұрын
Any idea why commands doesnt work with my bot? It doesnt recognize that i typed $hello
@pixegami
@pixegami 10 ай бұрын
Hmm, is it possible the Discord API version changed? Compare the version of Discord to the one being used in the video (although I'm not sure if I actually show it in there)...
@Manciek_
@Manciek_ 10 ай бұрын
@@pixegami nvm I just found out that .bot.event on_message() ovverite commands 😅
@novaplatoon5982
@novaplatoon5982 Жыл бұрын
hey when I tried doing the command it would not respond 14:37
@justecho5760
@justecho5760 Жыл бұрын
relatable
@jordantaylor5302
@jordantaylor5302 Жыл бұрын
same
@jordantaylor5302
@jordantaylor5302 Жыл бұрын
jk make sure when you declare your "!" thing theres no spaces like "! " or " !" this saved me hours and worked after i noticed i had a space of some sort
@dogereacts1271
@dogereacts1271 7 ай бұрын
my bot won't work and the error message has a problem with the async. do u know how to fix that?
@pixegami
@pixegami 7 ай бұрын
Sorry I'm not sure, it's been a quite since I worked on this. What's the error message say exactly?
@dogereacts1271
@dogereacts1271 7 ай бұрын
@@pixegamithis was the error message File "bot.py", line 11 async def on_ready(): ^ SyntaxError: invalid syntax
@dogereacts1271
@dogereacts1271 7 ай бұрын
do u know what it means? I'm clueless
@Unpluggedx89
@Unpluggedx89 6 ай бұрын
@@dogereacts1271What version of python were you using?
@dogereacts1271
@dogereacts1271 5 ай бұрын
@@Unpluggedx89 the newest
@Dhanush10101
@Dhanush10101 5 ай бұрын
Thanks for this video bro it's working with no issues and I got some idea about it once again thank you it's very useful to me ❤❤❤ but can you help me with in 20:41 i'm still can't figure it out to print the timer
@pixegami
@pixegami 5 ай бұрын
Thanks! Glad it's useful. What issue are you having with printing out the timer?
@Dhanush10101
@Dhanush10101 4 ай бұрын
@@pixegami ​ Hey thanks for your replay , so im a Beginner for python i cannot figure out the ' end session's end timer like human readable time and why are you using timedelta(seconds = duration)
@parrrkkkk
@parrrkkkk Жыл бұрын
im having this problem: AttributeError: 'NoneType' object has no attribute 'send'
@pixegami
@pixegami Жыл бұрын
What's the full stack trace? Did you initialize your bot properly?
@parrrkkkk
@parrrkkkk Жыл бұрын
@@pixegami no its ok now
@bongobears673
@bongobears673 17 күн бұрын
hey, it says that there is not module named discord. can you help?
@bongobears673
@bongobears673 17 күн бұрын
nevermind i got it working
@lukli425
@lukli425 2 ай бұрын
It doesnt run for me and It cant resolve discord dot ext
@pixegami
@pixegami 2 ай бұрын
Hmm, it could be because you might be using a newer version of the Discord library than what I used in the video, or you have it pointed to the wrong Python environment.
@Drk-Inky
@Drk-Inky 3 ай бұрын
i need pysilon discord
@SuperLimeWorld
@SuperLimeWorld 3 ай бұрын
It never prints the text when I run it! Edit: so it turns out it has to named 'on_ready' lmao "which thing has to be named on_ready?": Watch the tutorial, if you see something named "on_ready", don't change it, otherwise, it fails.
@pixegami
@pixegami 3 ай бұрын
Thanks for sharing the solution :)
@SuperLimeWorld
@SuperLimeWorld 3 ай бұрын
@@pixegami Np :3
@Meowicat
@Meowicat 2 ай бұрын
could you elaborate on this? which thing has to be named on_ready?
@SuperLimeWorld
@SuperLimeWorld 2 ай бұрын
@@Meowicat I have updated my comment to answer your question
@ferkovarinsky6507
@ferkovarinsky6507 Жыл бұрын
Why it isn't working in pydroid
@pixegami
@pixegami Жыл бұрын
I’m not too familiar with PyDroid, but I’m guessing it has OS or network limitations that are incompatible with the Discord library. You may have to try work on this ok a computer environment.
@fumingstargaming2508
@fumingstargaming2508 Жыл бұрын
I need help can i join your dc pls gimme link
@pixegami
@pixegami Жыл бұрын
Sorry I don't have a public Discord channel yet. I'll post an update if I do get around to making one.
@Theposhestcat
@Theposhestcat Жыл бұрын
does this work with pycharm?
@Sledgemasterrrr
@Sledgemasterrrr Жыл бұрын
Yes
@XaskyShow
@XaskyShow Жыл бұрын
Why that's not work on manjaro?
@pixegami
@pixegami Жыл бұрын
No idea... What error do you see?
@XaskyShow
@XaskyShow Жыл бұрын
@@pixegami no error, just not work.
@XaskyShow
@XaskyShow Жыл бұрын
@@pixegami he just don't making anything when typing command.
@hellonearth311
@hellonearth311 8 ай бұрын
it doesnt work bruh. apparently some "ssl certificate error"
@pixegami
@pixegami 8 ай бұрын
What's the full error?
@hellonearth311
@hellonearth311 8 ай бұрын
i uhh deleted the code now but i was getting the same error with sending emails in python and i created an unverified context using the ssl lib. we don't use that here so i probably have no way to fix it and i honestly dont really wanna make a bot anymore. thanks for the attention to people with errors i really appreciate it! i'll check out your other videos/tutorials.
@spionzentauer
@spionzentauer 7 ай бұрын
it says for me bot = commands.Bot(command_prefix="/", intents=discord.intents.all()) AttributeError: module 'discord' has no attribute 'intents' how do I fix this
@pixegami
@pixegami 7 ай бұрын
I think you might be using a different discord.py version than the one used in the tutorial. You'd either have to roll back to the same version, for find the equivalent to "discord.intents.all()" in your current library version.
Host a Python Discord Bot on AWS Lambda (Free and Easy)
21:40
What if my Intel CPU explodes??
14:20
Paul's Hardware
Рет қаралды 12 М.
БАБУШКИН КОМПОТ В СОЛО
00:23
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 17 МЛН
Top 5 High Paying Tech Skills to Learn in 2024
16:10
pixegami
Рет қаралды 13 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
How to Get Started with AWS • Crash Course
28:26
pixegami
Рет қаралды 3,5 М.
Difference between cookies, session and tokens
11:53
Valentin Despa
Рет қаралды 608 М.
Building a Discord Bot in Python (2024) Episode Four: Cogs
10:20
Paradoxial
Рет қаралды 1,8 М.
How To Code a Discord Music Bot
6:10
Max Codez
Рет қаралды 228 М.
Building a Discord Bot in Python (2024) Episode Two: Commands
8:33