def dm_only():
return commands.check(lambda ctx: ctx.guild is None)
python类check()的实例源码
def is_owner():
return commands.check(lambda ctx: is_owner_check(ctx.message))
def is_authorized_staff():
return commands.check(lambda ctx: is_authorized_staff_check(ctx.message))
def is_owner():
return commands.check(lambda ctx: is_owner_check(ctx.message))
def role_or_permissions(ctx, check, **perms):
if check_permissions(ctx, perms):
return True
ch = ctx.message.channel
author = ctx.message.author
if ch.is_private:
return False # can't have roles in PMs
role = discord.utils.find(check, author.roles)
return role is not None
def mod_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name in ('Luna Mod', 'Luna Admin', 'Bot Commander', 'Master Assassin'), **perms)
return commands.check(predicate)
def admin_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name in ('Luna Admin', 'Master Assassin'), **perms)
return commands.check(predicate)
# These two roles are for a specific server, just use 'Luna mod' and 'Luna
# admin'
def bot_main(token, queue, channel, prefix, desc):
"""Run bot."""
bot = AutomaBot(get=queue, update_channel=channel,
command_prefix=prefix,
description=desc, self_bot=False)
@bot.command(pass_context=True)
@commands.check(is_owner)
async def sleep(ctx):
await bot.change_presence(status=discord.Status.dnd, afk=True)
msg = 'Going to sleep. See you :wave:'
for comm in bot.commands:
if comm is not "wakeup":
bot.commands[comm].enabled = False
await bot.say(msg)
@bot.command(pass_context=True, hidden=True)
@commands.check(is_owner)
async def wakeup(ctx):
for comm in bot.commands:
if comm is not "wakeup":
bot.commands[comm].enabled = True
await bot.change_presence(status=discord.Status.online, afk=False)
msg = 'Goooooooooood morniiing vietnammmmmm :bomb:'
await bot.say(msg)
await bot.start(token)
def is_owner():
return commands.check(lambda ctx: is_owner_check(ctx.message))
# The permission system of the bot is based on a "just works" basis
# You have permissions and the bot has permissions. If you meet the permissions
# required to execute the command (and the bot does as well) then it goes through
# and you can execute the command.
# If these checks fail, then there are two fallbacks.
# A role with the name of Bot Mod and a role with the name of Bot Admin.
# Having these roles provides you access to certain commands without actually having
# the permissions required for them.
# Of course, the owner will always be able to execute commands.
def role_or_permissions(ctx, check, **perms):
if check_permissions(ctx, perms):
return True
ch = ctx.message.channel
author = ctx.message.author
if ch.is_private:
return False # can't have roles in PMs
role = discord.utils.find(check, author.roles)
return role is not None
def mod_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name == 'Bot Commander', **perms)
return commands.check(predicate)
def admin_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name == 'Bot Commander', **perms)
return commands.check(predicate)
def TO_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name in ('TO_Crew', 'Head TO', 'Staff'), **perms) #these roles are needed if you're a TO
return commands.check(predicate)
def gay_only():
return commands.check(lambda m: m.author.id in \
(162819866682851329, 97104885337575424, 150745989836308480))
def is_owner():
return commands.check(lambda ctx: is_owner_check(ctx.message))
# The permission system of the bot is based on a "just works" basis
# You have permissions and the bot has permissions. If you meet the permissions
# required to execute the command (and the bot does as well) then it goes through
# and you can execute the command.
# If these checks fail, then there are two fallbacks.
# A role with the name of Bot Mod and a role with the name of Bot Admin.
# Having these roles provides you access to certain commands without actually having
# the permissions required for them.
# Of course, the owner will always be able to execute commands.
def role_or_permissions(ctx, check, **perms):
if check_permissions(ctx, perms):
return True
ch = ctx.message.channel
author = ctx.message.author
if ch.is_private:
return False # can't have roles in PMs
role = discord.utils.find(check, author.roles)
return role is not None
def mod_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name in ('Bot Mod', 'Bot Admin'), **perms)
return commands.check(predicate)
def admin_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name == 'Bot Admin', **perms)
return commands.check(predicate)
def is_in_servers(*server_ids):
def predicate(ctx):
server = ctx.message.server
if server is None:
return False
return server.id in server_ids
return commands.check(predicate)
def bot_owner(ctx):
def check():
return ctx.author.id == 125435062127820800
return check()