-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Requirements
- Add
discord.pyto yourrequirements.txtand use pip to add it to your packages (See task 1) - Use the following code to create a simple Ping Pong command
import discord
client = discord.Client()
@client.event
async def on_ready():
print(f”Bot user {client.user} is ready.”)
@client.event
async def on_message(msg):
if msg.author == client.user:
return # Don’t respond to itself
if msg.content == “Ping”: # Check that the message content matches
await msg.channel.send(“Pong!”) # If it does, reply
client.run(TOKEN) #insert token here- Try it out by messaging
Pingon your bot dev channel
Security:
- Add
python-dotenvtorequirements.txt - Place your discord bot token into a
.envfile and import it into your program as an environment variable (see KoalaBot.py for an example of how to do it
Extension: virtual environment
- Instead of installing pip packages to your global python install, create a virtual environment in a
venvfolder, activate it, and then install all pip requirements within your new virtual environment - This allows any issues with one virtual environment not to affect any others
Metadata
Metadata
Assignees
Labels
No labels