Мой cog не работает для моего бота в discord.py - PullRequest
0 голосов
/ 22 апреля 2020

Вот код

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 arguement 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 arguement in {ctx.guild.name}')

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

Я не могу понять, что не так с этим Cog У меня есть другие Cog, которые отправляют сообщения нормально, но этот по какой-то причине не работает

Ответы [ 2 ]

0 голосов
/ 23 апреля 2020

Я не импортировал случайные данные, и мой ide просто показывал, что произошла ошибка, поэтому пришло время для нового ide

0 голосов
/ 22 апреля 2020

В декораторе команды укажите название команды: @commands.command(name="roll")

...