I decided to make a discord bot to have for me and my friends to play around with.
import discord
from discord import app_commands
import time
import random
def flip_coin():
flip = random.choice(["heads", "tails"])
return flip
def dice_roll():
roll = random.randint(1,6)
return roll
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
@client.event
async def on_message(message):
if message.author == client.user:
return
if "^joke" in message.content.lower() or "^9/11" in message.content.lower():
await message.channel.send("why were the twin towers sad?")
time.sleep(3)
await message.channel.send("because he ordered plane pizza!")
if "^pookie" in message.content.lower():
await message.channel.send("hey there pookstar.")
if "^flip" in message.content.lower():
flip = flip_coin()
await message.channel.send("fliping coin..")
time.sleep(3)
await message.channel.send(flip)
if "^roll" in message.content.lower():
roll = dice_roll()
await message.channel.send("rolling dice...")
time.sleep(2)
await message.channel.send(roll)
"""Game mechanic components"""
client.run("enter Token here")
This is the code used to make the discord bot.
I’ve leaned a few things, such as: the “await” command, which waits for other commands to go and meet certain requirements before being used.
I’ve learned more about the return function. and async function to sync in real time.