After you buy a hosting plan from Hostinger, select your new server from the VPS menu on the top bar. Then, complete the Hostinger VPS setup process via hPanel, our custom-made intuitive control panel. This will invalidate all old tokens belonging to your bot. Keep in mind that you will need to update your bot’s token where you used it before. Regardless of their scope, chatbots are generally fun, except when their responses to your complex queries have the intellectual depth of a cup of water.
Now that you’ve learned how to create an event handler, let’s walk through some different examples of handlers you can create. Once you’ve created your guild, you’d invite other users to populate it. A guild (or a server, as it is often called in Discord’s user interface) is a specific group of channels where users congregate to chat. For example, let’s say you’re managing a new Discord guild and a user joins for the very first time. Excited, you may personally reach out to that user and welcome them to your community. You might also tell them about your channels or ask them to introduce themselves.
Checking Command Predicates
Setting up and customizing a Discord bot depends on the specific bot and its developer. Many bots provide detailed instructions on how to use and customize them; some may even offer a user-friendly dashboard for customization. In this article, we’ll tell you how to create a Discord bot and add it to your server.
On Repl.it, most files you create are visible to anyone but .env files are only visible to you. Other people viewing a public repl will not be able to see the contents of the .env file. Now that you’ve created the bot user, we’ll start writing the Python code for the bot. Now that you’ve gotten the prerequisites out of the way, it’s time to create a new application that your bot can later be added to. People create communities referred to as servers in discord and other people can join these servers to hangout there to meet new people and talk about their interests.
How to Add Sad Words to the Bot
The next step you need to take is setting up an actual Discord bot application via Discord’s website. It is a good convention to choose a prefix that must apply to all commands to your bot. This creates a measure of namespacing for bots and helps avoid collision with other bots. Most bots include a help command, but imagine the mess if you had 10 bots in your guild and they all responded to help! As a prefix is not a foolproof solution, as there may be other bots that also use the same prefix. Most popular bots allow their prefix to be configured on a per-guild basis to help prevent collision.
- Our bot is going to mainly use text messages so we don’t need a lot of the permissions.
- Some may offer basic features for free but require payment for more advanced features or customizations.
- A Bot is a subclass of Client that adds a little bit of extra functionality that is useful when you’re creating bot users.
- This can help create a more engaging and interactive environment for users.
- For this tutorial, we’ll be creating a simple ‘Ping-Pong’ Discord bot which, as the name suggests, will reply with ‘Pong’ every time you type ‘Ping’.
Next, after the code to make the bot respond to the “$del” command, there is new code to respond to the “$list” command when sent as a Discord message. Like before, feel free to add more phrases of your choice to the list. I’m just using three items for now because later we’ll add the ability for users to add more encouraging phrases for the bot to use. Now we will implement the feature where the bot responds with encouraging messages when a user posts a message with a sad word.
Python-dotenv is a popular package that does this for us. Let’s go ahead and install this package so that we can secure our token. The on_message() function listens for any message that comes into any channel that the bot is in. Each message that is sent on the Discord side will trigger this function and send a Message object that contains a lot of information about the message that was sent. I’m using this function to simply check if the message that was sent is equal to “hello.” If it is, then our bot replies with a very welcoming phrase back.
A minimal bot with basic functionalities and if you want you can always extend the functionalities of this bot according to your needs. Another important use of Discord bots is to moderate channels and enforce server rules. This can help maintain a safe and welcoming environment for all users. To test your bot’s functionality, get back on your Discord server and try typing in “!