Booker5677
Booker5677

Reputation: 35

What does module not callable mean?

I have a command that you need a specific Role for, I've tried to write a code piece that tells the user of the command if they don't have the correct role,

however it throws a type error at me on bot start up saying the the 'module' is not callable?

What does 'module not callable' mean?

Here's the code;

@client.command()
@commands.has_role(875786906443599884)
async def sra(ctx, member: discord.Member = None):
if not member:
    member = ctx.author
amod = ctx.guild.get_role(848057125283954688)
loa = ctx.guild.get_role(848032714715561985)
await member.add_roles(amod)
await member.remove_roles(loa)
await ctx.send("Welcome back! " + str(member))
modReturnEmbed = discord.Embed(
    title='Return Log', description='This staff member has returned from leave! ' + str(member), color=0x000000)
modReturnEmbed.set_footer(text="LeaveManager Bot")
modReturnEmbed.set_author(name='Leave Manager')
botLogChannel = client.get_channel(874959002172268685)
await botLogChannel.send(embed=modReturnEmbed)

@commands.errors
async def missing_role(ctx, error):
if isinstance(error, commands.MissingRole):
    await ctx.send('You do not have permission to use this command!')

Upvotes: 0

Views: 110

Answers (2)

Chris
Chris

Reputation: 1321

Instead of having:

@commands.errors
async def missing_role(ctx, error):
if isinstance(error, commands.MissingRole):
    await ctx.send('You do not have permission to use this command!')

It should be

@sra.error #The name of the function instead of "commands" and error instead of errors
async def missing_role(ctx, error):
if isinstance(error, commands.MissingRole):
    await ctx.send('You do not have permission to use this command!')

Upvotes: 0

stijndcl
stijndcl

Reputation: 5650

however it throws a type error at me on bot start up saying the the 'module' is not callable? What does 'module not callable' mean?

You're trying to call() a module with commands.errors(), which refers to a file in the library (this is commands.errors). This means you're essentially doing file() which makes no sense. That's what that error means.

What you should be doing is @function_name.error, mind that there is no "s" at the end, it's error not errors.

@sra.error  # <- @sra, and "error" not "errorS"
async def missing_role(ctx, error):
    ...

Example for error handling from the docs: https://github.com/Rapptz/discord.py/blob/master/discord/ext/commands/errors.py

Upvotes: 2

Related Questions