Why i am getting a role exception?

Viewed 41
class Admin(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(name='create-embed')
    @commands.has_role(env.METACORE_MODERATOR_ROLE_ID)
    async def create_embed(self, ctx: commands.Context):
        embed_title = 'Test title'
        view = embed.view.CreateEmbedView()
        view.bot = self.bot
        view.author_id = ctx.author.id
        result_embed = discord.Embed(title=embed_title)
        embed_message = await ctx.send(embed=result_embed, view=view, ephemeral=True)
        view.embed = result_embed
        view.embed_message = embed_message

async def setup(bot):
    await bot.add_cog(Admin(bot))

So I have this code, env.METACORE_MODERATOR_ROLE_ID = 1019323835100700732. I gave a role with this id on my server, but I got the error -

discord.ext.commands.errors.MissingRole: Role '1019323835100700732' is required to run this command. 

And when I call ctx.message.author.roles, I am getting this role in array roles of user

And I don't understand why I am getting this error. Thx for help

1 Answers

You need to parse it as an integer.

@commands.has_role() can take role names aswell, so since it's a string your passing, discord.py assumes that the role name is "1019323835100700732"

You should do this instead:

@commands.has_role(int(env.METACORE_MODERATOR_ROLE_ID))
Related