This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

Discord.py | 01 – DEV Community


Merely discord.py is an API wrapper for discord APi written in python, For making discord bots.

Let’s begin by putting in discord.py
pip set up discord.py



The code

We have to import discord.py and outline our shopper(bot):

#importing discord.py.
import discord
from discord.ext import instructions
#defining our shopper(bot) variable and initializing the bot class.
#you'll be able to change the identify of the variable as you want 
shopper = instructions.Bot(command_prefix="!")
#operating our bot.
shopper.run("Your bot token")
Enter fullscreen mode

Exit fullscreen mode

You may get your bot token from here:





Then we’re going to make an occasion:

#This half isn't vital, However it's used to confirm that the bot had efficiently began.
#This merely prints I am alive when the bot is prepared.
@shopper.occasion
async def on_ready():
    print("I am Alive")

Enter fullscreen mode

Exit fullscreen mode

Defining our first command:

@shopper.command()
async def hello(ctx):
    await ctx.ship("Hey World")
#Merely the identify of the operate is the identify of the command
Enter fullscreen mode

Exit fullscreen mode



Producing invite hyperlink

Head to your bot utility:




In the permissions section you can choose permissions suitable with your bot, But i prefer using Administrator

The ultimate code:

import discord
from discord.ext import instructions

shopper = instructions.Bot(command_prefix = "!")

@shopper.occasion
async def on_ready():
    print("I am Alive")

@shopper.command()
async def hello(ctx):
    await ctx.ship("Hey World")

shopper.run("your token")

Enter fullscreen mode

Exit fullscreen mode

Operating the code:I am Alive

Image description
It is working.
The code
Thanks for studying, see you within the subsequent half.

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?