當前位置: 首頁>>代碼示例>>Python>>正文


Python discord.PermissionOverwrite方法代碼示例

本文整理匯總了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 
開發者ID:Xenon-Bot,項目名稱:xenon,代碼行數:18,代碼來源:backups.py

示例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) 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:21,代碼來源:temproom.py

示例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) 
開發者ID:bobloy,項目名稱:Fox-V3,代碼行數:27,代碼來源:infochannel.py

示例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)) 
開發者ID:Milotrince,項目名稱:discord-roombot,代碼行數:20,代碼來源:roomhost.py

示例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) 
開發者ID:python-discord,項目名稱:bot,代碼行數:15,代碼來源:test_silence.py

示例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) 
開發者ID:python-discord,項目名稱:bot,代碼行數:15,代碼來源:test_silence.py

示例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) 
開發者ID:jgayfer,項目名稱:spirit,代碼行數:14,代碼來源:events.py

示例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) 
開發者ID:CHamburr,項目名稱:modmail,代碼行數:13,代碼來源:configuration.py

示例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)) 
開發者ID:Kowlin,項目名稱:refactored-cogs,代碼行數:10,代碼來源:punish.py

示例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 
開發者ID:appu1232,項目名稱:Discord-Selfbot,代碼行數:8,代碼來源:mod.py

示例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 
開發者ID:kenng69,項目名稱:modmailbotkenng,代碼行數:15,代碼來源:bot.py

示例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) 
開發者ID:calebj,項目名稱:calebj-cogs,代碼行數:6,代碼來源:punish.py

示例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 
開發者ID:lehnification,項目名稱:Discord-SelfBot,代碼行數:34,代碼來源:mod.py

示例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)) 
開發者ID:smlbiobot,項目名稱:SML-Cogs,代碼行數:28,代碼來源:channelmanager.py

示例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)) 
開發者ID:NotSoSuper,項目名稱:NotSoBot,代碼行數:36,代碼來源:Moderation.py


注:本文中的discord.PermissionOverwrite方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。