in , ,

Create Your First Discord Bot With Python

hey guys Today I’ll tell you How To Create Your First Discord Bot With Python, I am pretty sure you always heard about this language known as “python”, because its pretty famous and useful. It is used in many fields some of the examples are – Instagram, Google, Spotfiy, Netflix, etc. According to Wikipedia “Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python’s design philosophy emphasizes code readability with its notable use of significant whitespace”.

While I was learning about python I noticed that it is very interesting language, so I decided to create guide and tutorials on Still I am not professional in developing discord bot using python but I’ll try my best to make you guys understand how to create discord bot using python.

How To Create A Bot Token

If you are newbie to discord developer world you might not know how to create a bot token, no worries I’ll be telling you how you can generate your bot token because without token you won’t be able to get your bot online.

To create a bot token go to discord developer portal, create a new application, add name and click on create.

After creating your first application go to bot section under the setting on left side.

Now click on add bot option on the right side. Your bot will be generated.

Now Copy the bot token and use it in this project. You will have to invite the bot in your testing server to do that go to OAuth2.

Under scopes tick on bot option.

Then setup the bot permission as per your need then copy the url and invite the bot to your server.

How To Create Your First Discord Bot With Python

First of all install in your IDE by using terminal, if you don’t know how to install then here is the link for guide to install

We will start with importing discord and importing commands from discord extension

import discord
from discord.ext import commands

Before going any further, it is mandatory to define client and we will be defining command prefix in it

client = commands.Bot(command_prefix="!", case_insensitive=True)

Now we will call event of on_ready and print something on console, I will be setting the bot status in on_ready event.

async def on_ready():
  print(f"I am ready to go - {}")
  await client.change_presence(activity=discord.Game(name=f"{client.command_prefix}ping"))

We created our first event to know that bot is ready, it means whenever you start the bot then the bot will send message to console. Between if you want to run the bot now then you can use“TOKEN”), But i will be creating the simple ping command before running the bot 😉

Now we will be creating command and for that we will be using @client.command()

async def _ping(ctx):
  ctx.send(f"Pong: {client.latency}")

At last we will add and add Token in it."TOKEN")
Create Your First Discord Bot With Python

Now we will be adding simple embed in ping command by using discord.Embed()

async def _ping(ctx):
  embed= discord.Embed(title=f"{} - PING LATENCY", description=f"Pong: {client.latency}", color=0xff2050)

Vi>Video Tutorial To Create Your First Discord Bot With Python

So>Source Code


In this post I have shown you how you can create your first python bot. I have made it as simple as possible and easy to understand, I have used as IDE in this tutorial you can use any IDE you want. If you are still facing some issue please let me know in the comments, I’ll be glad to help.


Related Posts

Written by Senpai

"This may be a virtual world,but I feel more alive here then in the real world"

Leave a Reply