我的齿轮无法在discord.py中为我的机器人工作

时间:2020-04-22 01:37:23

标签: python discord discord.py

这是代码

import discord
from discord.ext import commands

class roll(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def roll(self, ctx, output):
        count, size = output.split("d")
        size = int(size)
        count = int(count)
        counter = 0
        rolltotal = 0
        while counter < count:
            result = randint(1, size)
            rolltotal += result
            counter += 1
        eject = "You rolled {} on a {}!".format(rolltotal, output)
        await ctx.send(eject)

    @roll.error
    async def roll_error(self, ctx, error):
        if isinstance (error, commands.MissingRequiredArgument):
            await ctx.send(f'{ctx.author.mention}, please specify the size of the dice and ho many dice you\'re rolling EX: 1d20')
            await ctx.message.delete()
            print(f'{ctx.author.name} tried to roll dnd dice but didn\'t specify an argument in {ctx.guild.name}')
        elif isinstance (error, commands.BadArgument):
            await ctx.send(f'{ctx.author.mention}, please specify the size of the dice and ho many dice you\'re rolling EX: 1d20')
            await ctx.message.delete()
            print(f'{ctx.author.name} tried to roll dnd dice but gave a bad argument in {ctx.guild.name}')

def setup(bot):
    bot.add_cog(roll(bot))

我无法弄清楚此齿轮有什么问题,我还有其他齿轮可以很好地发送消息,但是由于某种原因,这个齿轮可能会发

2 个答案:

答案 0 :(得分:1)

在命令装饰器中,设置命令的名称:@commands.command(name="roll")

答案 1 :(得分:0)

我没有导入随机数,我的ide并没有显示出有错误,所以有时间换一个新的ide