An Interest In:
Web News this Week
- March 22, 2024
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
March 19, 2022 10:48 pm GMT
Original Link: https://dev.to/oxy_oxide/discordpy-01-31jh
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.pypip 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:
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
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:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To