So below code blocks server and user id in the list when they use ?hello
, so I am trying to raise custom error message. If user id is in list, it will tell User Blacklisted
and if server id is in list, it will tell Server has been Blacklisted
.
LIST_OF_USER_IDS = ['34534545546', '34534545546']
LIST_OF_SERVER_IDS = ['34534545546', '34534545546']
def blacklists(users, servers):
def predicate(ctx):
return ctx.message.author.id not in users and ctx.message.server.id not in servers
return commands.check(predicate)
@bot.command(pass_context=True)
@blacklists(LIST_OF_USER_IDS, LIST_OF_SERVER_IDS)
async def hello(ctx):
await bot.say("Hello {}".format(ctx.message.author.mention))
So I tried below code but getting error. I'm just a beginner so my code is not correct, so I need a help to fix this.
def blacklists(users, servers):
def predicate(ctx):
return ctx.message.author.id not in users and ctx.message.server.id not in servers
return commands.check(predicate)
try:
if ctx.message.author.id in LIST_OF_USER_IDS:
raise UserBlacklisted
elif ctx.message.server.id in LIST_OF_SERVER_IDS:
raise ServerBlacklisted
break
except UserBlacklisted:
await bot.send_message(ctx.message.channel, "User Blacklisted")
except ServerBlacklisted:
await bot.send_message(ctx.message.channel, "Server has been Blacklisted")