本文整理汇总了Python中discord.PermissionOverwrite方法的典型用法代码示例。如果您正苦于以下问题:Python discord.PermissionOverwrite方法的具体用法?Python discord.PermissionOverwrite怎么用?Python discord.PermissionOverwrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.PermissionOverwrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _overwrites_from_json
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def _overwrites_from_json(self, json):
overwrites = {}
for union_id, overwrite in json.items():
try:
union = await self.guild.fetch_member(int(union_id))
except discord.NotFound:
roles = list(
filter(lambda r: r.id == self.id_translator.get(union_id), self.guild.roles))
if len(roles) == 0:
continue
union = roles[0]
overwrites[union] = discord.PermissionOverwrite(**overwrite)
return overwrites
示例2: temproom
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def temproom(cmd, pld):
"""
:param cmd: The command object referenced in the command.
:type cmd: sigma.core.mechanics.command.SigmaCommand
:param pld: The payload with execution data and details.
:type pld: sigma.core.mechanics.payload.CommandPayload
"""
room_name = ' '.join(pld.args) or f'{pld.msg.author.display_name}\'s Room'
room_name = f'[Σ] {room_name}'
reason = f'Temporary voice channel by {pld.msg.author.name}#{pld.msg.author.discriminator}.'
temp_vc_cat = await get_category(cmd, pld.msg.guild)
if pld.msg.guild.me.permissions_in(temp_vc_cat).manage_channels:
perms = {'manage_channels': True, 'manage_roles': True, 'read_messages': True, 'connect': True, 'speak': True}
overwrites = {pld.msg.author: discord.PermissionOverwrite(**perms)}
await pld.msg.guild.create_voice_channel(room_name, reason=reason, overwrites=overwrites, category=temp_vc_cat)
response = ok(f'{room_name} created.')
else:
response = error('I can\'t create channels in that category.')
await pld.msg.channel.send(embed=response)
示例3: make_infochannel
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def make_infochannel(self, guild: discord.Guild):
botcount = await self.config.guild(guild).bot_count()
onlinecount = await self.config.guild(guild).online_count()
overwrites = {
guild.default_role: discord.PermissionOverwrite(connect=False),
guild.me: discord.PermissionOverwrite(manage_channels=True, connect=True),
}
channel = await guild.create_voice_channel(
"Placeholder", reason="InfoChannel make", overwrites=overwrites
)
await self.config.guild(guild).channel_id.set(channel.id)
if botcount:
botchannel = await guild.create_voice_channel(
"Placeholder", reason="InfoChannel botcount", overwrites=overwrites
)
await self.config.guild(guild).botchannel_id.set(botchannel.id)
if onlinecount:
onlinechannel = await guild.create_voice_channel(
"Placeholder", reason="InfoChannel onlinecount", overwrites=overwrites
)
await self.config.guild(guild).onlinechannel_id.set(onlinechannel.id)
await self.update_infochannel(guild)
示例4: voice_channel
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def voice_channel(self, ctx, *args):
c = self.get_context(ctx, args)
if c.voice_channel:
await c.voice_channel.delete()
await ctx.send(c.settings.get_text('deleted_voice_channel'))
else:
category = await get_rooms_category(ctx.guild, c.settings)
voice_channel = await ctx.guild.create_voice_channel(
c.room.activity,
category=category,
position=0,
bitrate=c.settings.bitrate * 1000,
overwrites={
ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False),
ctx.guild.me: discord.PermissionOverwrite(move_members=True),
c.role: discord.PermissionOverwrite(read_messages=True) })
c.room.update('voice_channel_id', voice_channel.id)
await ctx.send(c.settings.get_text('new_voice_channel').format(voice_channel.name))
示例5: test_silence_private_preserves_permissions
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def test_silence_private_preserves_permissions(self):
"""Previous permissions were preserved when channel was silenced."""
channel = MockTextChannel()
# Set up mock channel permission state.
mock_permissions = PermissionOverwrite()
mock_permissions_dict = dict(mock_permissions)
channel.overwrites_for.return_value = mock_permissions
await self.cog._silence(channel, False, None)
new_permissions = channel.set_permissions.call_args.kwargs
# Remove 'send_messages' key because it got changed in the method.
del new_permissions['send_messages']
del mock_permissions_dict['send_messages']
self.assertDictEqual(mock_permissions_dict, new_permissions)
示例6: test_unsilence_private_preserves_permissions
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def test_unsilence_private_preserves_permissions(self, _):
"""Previous permissions were preserved when channel was unsilenced."""
channel = MockTextChannel()
# Set up mock channel permission state.
mock_permissions = PermissionOverwrite(send_messages=False)
mock_permissions_dict = dict(mock_permissions)
channel.overwrites_for.return_value = mock_permissions
await self.cog._unsilence(channel)
new_permissions = channel.set_permissions.call_args.kwargs
# Remove 'send_messages' key because it got changed in the method.
del new_permissions['send_messages']
del mock_permissions_dict['send_messages']
self.assertDictEqual(mock_permissions_dict, new_permissions)
示例7: get_events_channel
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def get_events_channel(self, guild):
"""Return the events channel if it exists, otherwise create one and return it"""
for channel in guild.channels:
if channel.name == "upcoming-events":
return channel
# Need to make sure the bot can still send messages in the events channel
overwrites = {
guild.default_role: discord.PermissionOverwrite(send_messages=False, add_reactions=True),
guild.me: discord.PermissionOverwrite(send_messages=True, add_reactions=True)
}
return await guild.create_text_channel("upcoming-events", overwrites=overwrites)
示例8: __init__
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def __init__(self, bot):
self.bot = bot
self.role_permission = discord.PermissionOverwrite(
read_messages=True,
read_message_history=True,
send_messages=True,
embed_links=True,
attach_files=True,
add_reactions=True,
)
self.default_role_permission = discord.PermissionOverwrite(read_messages=False)
示例9: new_channel
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def new_channel(self, c):
if 'Punished' in [r.name for r in c.server.roles]:
if c.type.name == 'text':
perms = discord.PermissionOverwrite()
perms.send_messages = False
r = discord.utils.get(c.server.roles, name='Punished')
await self.bot.edit_channel_permissions(c, r, perms)
log.debug('Punished role created on channel: {}'.format(c.id))
示例10: are_overwrites_empty
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def are_overwrites_empty(self, overwrites):
"""There is currently no cleaner way to check if a
PermissionOverwrite object is empty"""
original = [p for p in iter(overwrites)]
empty = [p for p in iter(discord.PermissionOverwrite())]
return original == empty
示例11: overwrites
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def overwrites(self, ctx, modrole=None):
'''Permision overwrites for the guild.'''
overwrites = {
ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False)
}
if modrole:
overwrites[modrole] = discord.PermissionOverwrite(read_messages=True)
else:
for role in self.guess_modroles(ctx):
overwrites[role] = discord.PermissionOverwrite(read_messages=True)
return overwrites
示例12: overwrite_from_dict
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def overwrite_from_dict(data):
allow = discord.Permissions(data.get('allow', 0))
deny = discord.Permissions(data.get('deny', 0))
return discord.PermissionOverwrite.from_pair(allow, deny)
示例13: mute
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def mute(self, ctx, mem: str):
"""Mute a Member."""
member = getUser(ctx, mem)
if member:
if not utils.find(lambda r: "mute" in r.name.lower(), ctx.message.guild.roles):
if not utils.find(lambda r: "Muted" == r.name, ctx.message.guild.roles):
perms = utils.find(lambda r: "@everyone" == r.name, ctx.message.guild.roles).permissions
role = await ctx.guild.create_role(name="Muted", permissions=perms)
log.info('Created role: Muted')
for channel in ctx.guild.text_channels:
await channel.set_permissions(role, overwrite=discord.PermissionOverwrite(send_messages=False, add_reactions=False))
for channel in ctx.guild.voice_channels:
await channel.set_permissions(role, overwrite=discord.PermissionOverwrite(speak=False))
log.info('Prepared Mute role for mutes in channels')
role = utils.find(lambda r: "Muted" == r.name, ctx.message.guild.roles)
else:
role = utils.find(lambda r: "mute" in r.name.lower(), ctx.message.guild.roles)
if role not in member.roles:
roles = member.roles
roles.append(role)
asyncio.sleep(0.5)
await member.edit(roles=roles)
log.info(f'Muted {member}')
e = discord.Embed(color=embedColor(self))
e.set_author(name="\N{SPEAKER WITH CANCELLATION STROKE} Muted " + str(member))
await edit(ctx, embed=e)
else:
await edit(ctx, content="\N{HEAVY EXCLAMATION MARK SYMBOL} Already muted", ttl=5)
# Mute a Member
示例14: create_user
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def create_user(self, ctx, name, user: discord.Member, after: discord.Channel = None):
"""User specific channel.
Everyone can read but only one person can write.
"""
server = ctx.message.server
channel = await self.bot.create_channel(
server,
name,
discord.ChannelPermissions(
target=server.default_role,
overwrite=discord.PermissionOverwrite(
read_messages=True,
send_messages=False
)
),
discord.ChannelPermissions(
target=user,
overwrite=discord.PermissionOverwrite(
send_messages=True
)
),
type=discord.ChannelType.text
)
await self.bot.say("Channel created: {}".format(channel))
示例15: mute
# 需要导入模块: import discord [as 别名]
# 或者: from discord import PermissionOverwrite [as 别名]
def mute(self, ctx, *users:discord.User):
"""Mute a User"""
if ctx.message.server.me.permissions_in(ctx.message.channel).manage_channels == False:
await self.bot.say("Sorry, I do not have the manage_channels permission\n**Aborting**")
return
for user in users:
if ctx.message.author.permissions_in(ctx.message.channel).administrator:
await self.bot.say(':no_entry: `{0}` cannot be muted.'.format(user))
continue
if ctx.message.server in self.muted_users:
if user in self.muted_users[ctx.message.server]:
await self.bot.say('`{0}` is already muted!'.format(user))
continue
count = 0
for channel in ctx.message.server.channels:
perms = user.permissions_in(channel)
if perms.read_messages == False:
continue
overwrite = discord.PermissionOverwrite()
overwrite.send_messages = False
try:
await self.bot.edit_channel_permissions(channel, user, overwrite)
await asyncio.sleep(0.21)
count += 1
except:
if count == 0:
await self.bot.say(":no_entry: Bot does not have permission")
return
continue
if ctx.message.server.id not in self.muted_users:
self.muted_users[ctx.message.server] = [user]
else:
self.muted_users[ctx.message.server] += user
await self.bot.say("ok, muted `{0}`".format(user))