Build your own Discord Bot with Python! #1 (BasicBot)

in #utopian-io6 years ago (edited)

This is an introduction to a series of tutorials regarding Discord's Python API and building bots in it.

I'm an author of a Steem integrated Discord bot for @littleboy's steemit-moderation project. You can find my post about it here.

If you're a Discord user, the chances are you have encountered bots in the past. Maybe you installed some on your channel, maybe you saw them on big, public channels doing some great work. Either way, some of you probably thought that there are ways to improve them, but since their developers are very busy it's unlikely to happen. What should you do then?

Why not build your own bot?

All you need is a little bit of Python knowledge and the motivation to learn. Welcome, to the first tutorial regarding this issue, where you will learn how to code functions into a simple, open-source bot: BasicBot by Habchy.
DiscordBot

In this tutorial you will learn how to:

  • Setup BasicBot.
  • Learn why BasicBot is very powerfull and a great tool for beginners.
  • Write your first, simple script for the bot to do!

Let's get started!

  • Setup BasicBot.
    I could tell you exactly what to do and spend 30 minutes writing this part, but I can do something far better, that will benefit both of us. BasicBot's creator - Habchy has prepared a detailed tutorial with gifs tutoring you through the setup experience. It's easy to follow and tells you all you need to know to launch your BasicBot! You can find it here!

  • Learn why BasicBot is very powerfull and a great tool for beginners.
    While using existing code is nothing new for programmers, especially Python programmers that import dozens of packages per a single file, BasicBot is just what it claims to be. A basic bot that will show you what Discord bots can do when combined with Python. It has it's fair bit of issues, but the fact that you won't need to worry about basic functionality is great for the sake of this begginer-style tutorial.

basicbot1.PNG

BasicBot comes with an example of a simple command - Ping. Before we test it though, you need to setup your command prexif. Most bots use !, so let's do the same. Go to the top of the code and change this variable:
basicbot2.PNG

Try to run this code after you go through the setup tutorial and write !ping on your discord channel.
ping pong.PNG
Congratulations! You've just discovered one of two basic functionalities of discord bots - commands (the other one being events, which is also present in the code, but in a much different setting; I'll be talking about events in the next tutorial) . This is generally what you'll be using to code most of your bot functionality! Let's set one up ourselves!

basicbot3.PNG

Add this code below the ping function and type in !hello_steem. If you have any deductive skills or python knowledge, based on the ping function you should be able to tell what it does.

There are many things your bot can do, from sending messages, through removing them, all the way to playing music. By the end of this series you will know how to do all of these, but as this tutorial is a little long, I'll end it there. When I learned coding from tutorials, I was always happy when I got a bit of homework, so I'll give some to you as well.
Before you go to the next tutorial, please look through the official discord.py documentation and build a command of your choosing.

Don't worry if it doesn't work yet or if you don't understand what you're reading - it requires advanced python knowledge (like usage of generators and await functions) and I'll give you a hand the next time you come around here. For now just build the best thing you can without pulling your hair out. See you then!

Proceed to part 2 here.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Excellent tutorial, thank you for sharing your knowledge.
Upvoted and resteemed. Do you want to know why? Visit @pf-coin.

I appreciate the resteem, thanks!

You're welcome! Thank you for your support. ;-)

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @jestemkioskiem I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.032
BTC 63572.67
ETH 3086.22
USDT 1.00
SBD 3.86