[Python] How to make Discord bot? (Beginner Friendly)
Use something like Visual Studio Code, Sublime Text or Atom.
Then you once you have installed Discord or opened it.
Make a server and make sure its organised so you know what you are doing. Use the Discord Developers Portal to make a bot.
discord.py
.discord.py
.pip install discord.py
pip3 install discord.py
import discord
import discord
client = discord.Client()
import discord
client = discord.Client()
@client.event
async def on_ready():
print("The bot is ready!")
The bot is ready!
. It runs anything that is in the function. Cool, right? We can use this to do other things, too, such as set a play status for the bot, as so:import discord
client = discord.Client()
@client.event
async def on_ready():
print("The bot is ready!")
await client.change_presence(game=discord.Game(name="Making a bot"))
change_presence
method on the Discord client, it changes the presence of the client to show that it is playing the game “Making a bot”, since we created a Game object with the name “Making a bot”.import discord
client = discord.Client()
@client.event
async def on_ready():
print("The bot is ready!")
await client.change_presence(game=discord.Game(name="Making a bot"))
@client.event
async def on_message(message):
if message.author == client.user:
return
import discord
client = discord.Client()
@client.event
async def on_ready():
print("The bot is ready!")
await client.change_presence(game=discord.Game(name="Making a bot"))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content == "Hello":
await client.send_message(message.channel, "World")
send_message
method takes two parameters, the channel to send the message to, and the message to send (in the form of a string). The bot awaits until it sends this message, then looks for another response. Amazing! We just made our first bot using discord.py, but how can we connect it to our server now? Well, there’s one more piece of code we forgot.client.run()
function, which runs the bot. It only takes one parameter, which is your bot’s token, which you should have seen earlier. Put this token in, and your bot should start up when you run the program!import discord
client = discord.Client()
@client.event
async def on_ready():
print("The bot is ready!")
await client.change_presence(game=discord.Game(name="Making a bot"))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content == "Hello":
await client.send_message(message.channel, "World")
client.run(TOKEN)
Comment if you want more tutorials like this!
Yuma-Tsushima07
/
Yuma-Tsushima07
Readme file
Welcome to Yuma-Tsushima's Github page!
About Myself
Hello, my name is Yuma-Tsushima (frequently shortened to Yuma). I am an ambitious coder, and I enjoy coding in JavaScript (mainly). I also love making websites using HTML, CSS and (of course) JS! I started programming (self taught) at the age of 13. Originally, I came from the creative field ; I draw/sing/animate/make music.
Talents and Hobbies
I love drawing (I have been drawing all of my life). I play strategy games, I code and I do CTFs! I am also good at animation, making AMVs and image editing. My favourite game is Mindustry, followed by Flow Free and Sudoku. I love watching anime (I love Code Geass - I relate to Lelouch a lot) and I aspire to create my own anime!
Check out my work!:
❯ Soundcloud : 0c7av3h4ck5
❯ Discord : {CyberArtByte}
❯ Artwork : AcceleratorArts07
Recent Medium…
18