如何在 discord.py 的 Discord 机器人中正确实施随机整数命令?

How can I correctly implement a random integer command in a Discord bot with discord.py?

我最近决定尝试用 discord.py 在 Discord 中制作一个机器人。机器人本身已成功创建并集成到公会中,但我在执行某些命令时遇到了一些问题。

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'))

当我在公会中输入“?ping”时,机器人会回复“pong”,但是当我输入“?rand a b”时,a < b,机器人不会响应。用任何整数或字符串替换“random.randint(arg1,arg2)”会导致机器人用该整数或字符串回复。

如何使用机器人命令正确实现 randint() 函数?

将 arg1 和 arg2 从字符串转换为整数,然后再将它们传递给 randint。