0
import os
import discord
import json
from discord.ext import commands, check

def check_if_user_has_premium(ctx):
    with open("premium_users.json") as f:
        premium_users_list = json.load(f)
        if ctx.author.id not in premium_users_list:
            return False

    return True

@bot.command()
@check(check_if_user_has_premium)
async def apremiumcommand(ctx):
    await ctx.send("Hello premium user!")

@apremiumcommand.error
async def apremiumcommand_error(ctx, error):
    if isinstance(error, commands.CheckFailure):
            await ctx.send("Sorry, but you are not a premium user!")
    else:
        raise error


bot.run(os.getenv("TOKEN"))

I am getting this error:

Traceback (most recent call last): File "main.py", line 269, in @check(check_if_user_has_premium) TypeError: 'module' object is not callable

1 Answers1

1

As you can see in the documentation, You should have done

@commands.check(f) and not @check(f)

You also need to remove the , check from the import line since that function only exists under the module discord.ext.commands

Jonathan1609
  • 1,809
  • 1
  • 5
  • 22