If you’re familiar with online communities, you’ve likely encountered Discord. Whether you’re a member or an owner, you’ve probably seen bots managing these communities. In this article, we will guide you through setting up your Discord developer portal account and creating a basic Discord bot. This minimal bot will have basic functionalities, and you can always extend its features to meet your needs.
What is Discord?
Discord is a free chat app that offers various communication options such as voice, video, and text chat. It’s used by millions of people worldwide for both professional and recreational purposes. On Discord, people create communities called servers, where others can join to socialize, meet new people, and discuss shared interests. Discord also allows the creation of private servers, where only invited individuals can join, making it a great tool for private conversations among friends and close contacts.
Within these servers, owners can create multiple channels, which can be text, audio, or video-based. Each channel serves as a dedicated space for discussions on specific topics, helping keep conversations organized and focused.
What are Discord Bots?
With more than 10 million daily users, Discord’s popularity is booming. As servers grow, managing them becomes increasingly challenging for admins. This is where Discord bots come into play. Bots can perform various administrative tasks to enhance user experience, such as:
- Welcoming new members.
- Answering frequently asked questions.
- Banning toxic users.
- Replying to, sending, and deleting messages.
- Managing user roles within the server.
For large communities, admins often enable multiple bots to help manage their servers effectively. By following this tutorial, you can create your own Discord bot.
How to Make a Discord Bot in Python
To start, you need a dedicated server where your bot will operate, typically on a single channel within that server. If you don’t already have a Discord account, you can create one by visiting Discord’s website.
Step 1: Create a Server
- Click the “Add Server” (plus) button on the left sidebar.
- This will open the server creation interface.
- Choose a template for your server and follow the prompts to complete the setup.
Once your server is ready, you can proceed to create your bot. The bot will be set up to perform basic functionalities, which you can expand upon as needed. By automating tasks and improving user interaction, your Discord bot will help manage and enhance your server’s community effectively.
Step 2: Choose if you using this server for fun or community.
Step 3: Select a catchy and memorable name for your server. If it’s for a community or business, you can use the name of your community or company.
Step 4: You Server is now created
Creating A Bot With your account and server ready, we can now proceed to create our first bot on the Discord Developer Portal. This portal is a platform provided by Discord for developers who want to extend Discord’s capabilities and build more advanced features, such as bots.
Step 1: Log in to the Portal: Visit https://discord.com/developers/applications and log in with your Discord account that has the server for which you want to create the bot.
Step 2: An application in Discord refers to new functionality, such as a bot. To create your first bot, click on “New Application,” and choose a name for your application. Keep in mind that the application name will be the name of your bot.

Step 3: Creating a Bot click on Bot in the left sidebar and click on Add Bot.
Step 4: A popup will open which will ask you if you really want to add a bot click on Yes, Do it.
Step 5: Copy the token with the COPY button given below this token is used to authorize programs with discord.
Note: Never Share your token with anybody!

Install discord.py Library:
- Open your terminal or command prompt and install the
discord.pylibrary using pip
pip install discord.py
Bot Code:
Create a new Python file (e.g., bot.py) and add the following code:
import discord
from discord.ext import commands
# Replace 'YOUR_BOT_TOKEN' with your bot's token
TOKEN = 'YOUR_BOT_TOKEN'
# Intents are necessary for certain features such as member updates
intents = discord.Intents.default()
intents.messages = True
intents.guilds = True
# Create a bot instance
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'Bot is ready. Logged in as {bot.user}')
@bot.event
async def on_message(message):
# Ignore messages sent by the bot itself
if message.author == bot.user:
return
if message.content.startswith('!hello'):
await message.channel.send(f'Hello {message.author.name}!')
# Process commands
await bot.process_commands(message)
@bot.command()
async def ping(ctx):
await ctx.send('Pong!')
@bot.command()
async def say(ctx, *, message: str):
await ctx.send(message)
# Run the bot
bot.run(TOKEN)
Explanation of the Code:
- Import the Necessary Libraries:
discordanddiscord.ext.commandsare imported to use thediscord.pylibrary functionalities.
- Token and Intents:
TOKENis where you place your bot’s token.intentsare necessary for certain features such as member updates. Here, we enable default intents and allow messages and guilds intents.
- Create a Bot Instance:
commands.Botis used to create an instance of the bot with a command prefix (!in this case) and the specified intents.
- Define Event Handlers:
on_readyevent handler: This event triggers when the bot has successfully connected to Discord.on_messageevent handler: This event triggers whenever a message is sent in a server where the bot is present. It checks if the message starts with!helloand responds accordingly.
- Define Commands:
@bot.command: This decorator is used to define a command. For example,pingcommand responds with “Pong!” andsaycommand repeats the given message.
- Run the Bot:
bot.run(TOKEN)is used to run the bot using the provided token.
Running Your Bot
- Save the Python file and run it using
python bot.py
Your bot should now be online and responding to commands in your server.
Adding Your Bot to a Server
- In the Discord Developer Portal, navigate to the “OAuth2” section and select the “URL Generator” option.
- Under “OAuth2 URL Generator,” select the “bot” scope and choose the permissions you want to grant to your bot.
- Copy the generated URL, paste it into your browser, and select the server where you want to add the bot.
By following these steps, you should have a functional Discord bot written in Python that can respond to basic commands. You can further extend the bot’s functionalities by adding more commands and event handlers as needed.
Output:

Conclusion
Creating a Discord bot in Python is a rewarding and educational experience that can significantly enhance your programming skills and understanding of asynchronous operations. With the help of the discord.py library, you can easily set up and customize a bot to perform various automated tasks, interact with users, and manage your Discord server efficiently. By following the detailed steps from setting up your developer account to writing and running your bot’s code, you gain practical insights into how APIs and webhooks function.
This knowledge is not only useful for managing online communities but also provides a strong foundation for more advanced programming projects in the future. Whether you’re building a bot for fun, to manage a community, or to automate repetitive tasks, mastering the creation of a Discord bot in Python opens up a world of possibilities.





Leave a Reply