mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 18:59:09 +00:00
[commands] Don't use removed is_private attribute in core decorators.
This commit is contained in:
parent
496f5d0472
commit
3f06cf9e81
@ -321,7 +321,7 @@ class Command:
|
|||||||
if not self.enabled:
|
if not self.enabled:
|
||||||
raise DisabledCommand('{0.name} command is disabled'.format(self))
|
raise DisabledCommand('{0.name} command is disabled'.format(self))
|
||||||
|
|
||||||
if self.no_pm and ctx.message.channel.is_private:
|
if self.no_pm and not isinstance(ctx.channel, discord.abc.GuildChannel):
|
||||||
raise NoPrivateMessage('This command cannot be used in private messages.')
|
raise NoPrivateMessage('This command cannot be used in private messages.')
|
||||||
|
|
||||||
if not ctx.bot.can_run(ctx):
|
if not ctx.bot.can_run(ctx):
|
||||||
@ -762,12 +762,10 @@ def has_role(name):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
msg = ctx.message
|
if not isinstance(ctx.channel, discord.abc.GuildChannel):
|
||||||
ch = msg.channel
|
|
||||||
if ch.is_private:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
role = discord.utils.get(msg.author.roles, name=name)
|
role = discord.utils.get(ctx.author.roles, name=name)
|
||||||
return role is not None
|
return role is not None
|
||||||
|
|
||||||
return check(predicate)
|
return check(predicate)
|
||||||
@ -795,12 +793,10 @@ def has_any_role(*names):
|
|||||||
await bot.say('You are cool indeed')
|
await bot.say('You are cool indeed')
|
||||||
"""
|
"""
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
msg = ctx.message
|
if not isinstance(ctx.channel, discord.abc.GuildChannel):
|
||||||
ch = msg.channel
|
|
||||||
if ch.is_private:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
getter = functools.partial(discord.utils.get, msg.author.roles)
|
getter = functools.partial(discord.utils.get, ctx.author.roles)
|
||||||
return any(getter(name=name) is not None for name in names)
|
return any(getter(name=name) is not None for name in names)
|
||||||
return check(predicate)
|
return check(predicate)
|
||||||
|
|
||||||
@ -828,9 +824,8 @@ def has_permissions(**perms):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
msg = ctx.message
|
ch = ctx.channel
|
||||||
ch = msg.channel
|
permissions = ch.permissions_for(ctx.author)
|
||||||
permissions = ch.permissions_for(msg.author)
|
|
||||||
return all(getattr(permissions, perm, None) == value for perm, value in perms.items())
|
return all(getattr(permissions, perm, None) == value for perm, value in perms.items())
|
||||||
|
|
||||||
return check(predicate)
|
return check(predicate)
|
||||||
@ -841,8 +836,8 @@ def bot_has_role(name):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
ch = ctx.message.channel
|
ch = ctx.channel
|
||||||
if ch.is_private:
|
if not isinstance(ch, discord.abc.GuildChannel):
|
||||||
return False
|
return False
|
||||||
me = ch.guild.me
|
me = ch.guild.me
|
||||||
role = discord.utils.get(me.roles, name=name)
|
role = discord.utils.get(me.roles, name=name)
|
||||||
@ -854,8 +849,8 @@ def bot_has_any_role(*names):
|
|||||||
any of the roles listed.
|
any of the roles listed.
|
||||||
"""
|
"""
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
ch = ctx.message.channel
|
ch = ctx.channel
|
||||||
if ch.is_private:
|
if not isinstance(ch, discord.abc.GuildChannel):
|
||||||
return False
|
return False
|
||||||
me = ch.guild.me
|
me = ch.guild.me
|
||||||
getter = functools.partial(discord.utils.get, me.roles)
|
getter = functools.partial(discord.utils.get, me.roles)
|
||||||
@ -867,9 +862,9 @@ def bot_has_permissions(**perms):
|
|||||||
the permissions listed.
|
the permissions listed.
|
||||||
"""
|
"""
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
ch = ctx.message.channel
|
guild = ctx.guild
|
||||||
me = ch.guild.me if not ch.is_private else ctx.bot.user
|
me = guild.me if guild is not None else ctx.bot.user
|
||||||
permissions = ch.permissions_for(me)
|
permissions = ctx.channel.permissions_for(me)
|
||||||
return all(getattr(permissions, perm, None) == value for perm, value in perms.items())
|
return all(getattr(permissions, perm, None) == value for perm, value in perms.items())
|
||||||
return check(predicate)
|
return check(predicate)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user