0
votes

I recently decided to try making a bot in Discord with discord.py. The bot itself has been successfully created and integrated into the guild, but I'm having some trouble implementing certain commands.

import discord
from discord.ext import commands
import os
import random

bot = commands.Bot(command_prefix = "?")

@bot.command()
async def ping(ctx): 
      await ctx.channel.send("pong")

@bot.command()
async def rand(ctx, arg1, arg2):
      await ctx.channel.send(random.randint(arg1,arg2))

bot.run(os.getenv('TOKEN'))

When I type "?ping" in my guild, the bot replies with "pong", but when I type "?rand a b", such that a < b, the bot does not respond. Replacing "random.randint(arg1,arg2)" with any integer or string results in the bot replying with that integer or string.

How do I correctly implement the randint() function using a bot command?

1

1 Answers

0
votes

Convert arg1 and arg2 from strings to integers before passing them to randint.