Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 19, 2022 10:48 pm GMT

Discord.py | 01

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

Let's start by installing discord.py
pip install discord.py

The code

We need to import discord.py and define our client(bot):

#importing discord.py.import discordfrom discord.ext import commands#defining our client(bot) variable and initializing the bot class.#you can change the name of the variable as you like client = commands.Bot(command_prefix="!")#running our bot.client.run("Your bot token")

You can get your bot token from here:





Then we are going to make an event:

#This part is not important, But it is used to verify that the bot had successfully started.#This simply prints I'm alive when the bot is ready.@client.eventasync def on_ready():    print("I'm Alive")

Defining our first command:

@client.command()async def hi(ctx):    await ctx.send("Hello World")#Simply the name of the function is the name of the command

Generating invite link

Head to your bot application:




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

The final code:

import discordfrom discord.ext import commandsclient = commands.Bot(command_prefix = "!")@client.eventasync def on_ready():    print("I'm Alive")@client.command()async def hi(ctx):    await ctx.send("Hello World")client.run("your token")

Running the code:I'm Alive

Image description
It's working.
The code
Thanks for reading, see you in the next part.


Original Link: https://dev.to/oxy_oxide/discordpy-01-31jh

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To