Welcome back, today we are gonna show to how to make a game about guessing a random number.
So follow my steps.
Lets get back to replit and choose the bot project.
And we are gonna take the from random import randint and put it all the way up the first lines
import discord from discord.ext import commands from random import randint
@bot.command(name="roll") async def roll(ctx): await ctx.send(f"Rolled number: {randint(1, 6)}")
And we are gonna declare a variable, so name the variable number = randint(0, 9)
import discord from discord.ext import commands from random import randint number = randint(0, 9)
Now we are gonna make a command so we could guess the number.
@bot.command(name='guessnumber') async def guessnumber(ctx, guess: str): global number if (int(guess) == number): await ctx.send("You guessed the number!") number = randint(0, 9) else: await ctx.send("Wrong number, try again.")
Now go press the run button and go back to discord where the bot is in.
And as you can see, the code worked!