当前位置: 首页>>代码示例>>Python>>正文


Python discord.CategoryChannel方法代码示例

本文整理汇总了Python中discord.CategoryChannel方法的典型用法代码示例。如果您正苦于以下问题:Python discord.CategoryChannel方法的具体用法?Python discord.CategoryChannel怎么用?Python discord.CategoryChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在discord的用法示例。


在下文中一共展示了discord.CategoryChannel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_guild_channel_delete

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def on_guild_channel_delete(self, channel: GUILD_CHANNEL) -> None:
        """Log channel delete event to mod log."""
        if channel.guild.id != GuildConstant.id:
            return

        if isinstance(channel, discord.CategoryChannel):
            title = "Category deleted"
        elif isinstance(channel, discord.VoiceChannel):
            title = "Voice channel deleted"
        else:
            title = "Text channel deleted"

        if channel.category and not isinstance(channel, discord.CategoryChannel):
            message = f"{channel.category}/{channel.name} (`{channel.id}`)"
        else:
            message = f"{channel.name} (`{channel.id}`)"

        await self.send_log_message(
            Icons.hash_red, Colours.soft_red,
            title, message
        ) 
开发者ID:python-discord,项目名称:bot,代码行数:23,代码来源:modlog.py

示例2: __init__

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def __init__(self, bot: Bot):
        super().__init__()

        self.bot = bot

        # Categories
        self.available_category: discord.CategoryChannel = None
        self.in_use_category: discord.CategoryChannel = None
        self.dormant_category: discord.CategoryChannel = None

        # Queues
        self.channel_queue: asyncio.Queue[discord.TextChannel] = None
        self.name_queue: t.Deque[str] = None

        self.name_positions = self.get_names()
        self.last_notification: t.Optional[datetime] = None

        # Asyncio stuff
        self.queue_tasks: t.List[asyncio.Task] = []
        self.ready = asyncio.Event()
        self.on_message_lock = asyncio.Lock()
        self.init_task = self.bot.loop.create_task(self.init_cog()) 
开发者ID:python-discord,项目名称:bot,代码行数:24,代码来源:help_channels.py

示例3: on_guild_channel_create

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def on_guild_channel_create(self, channel: GUILD_CHANNEL) -> None:
        """Log channel create event to mod log."""
        if channel.guild.id != GuildConstant.id:
            return

        if isinstance(channel, discord.CategoryChannel):
            title = "Category created"
            message = f"{channel.name} (`{channel.id}`)"
        elif isinstance(channel, discord.VoiceChannel):
            title = "Voice channel created"

            if channel.category:
                message = f"{channel.category}/{channel.name} (`{channel.id}`)"
            else:
                message = f"{channel.name} (`{channel.id}`)"
        else:
            title = "Text channel created"

            if channel.category:
                message = f"{channel.category}/{channel.name} (`{channel.id}`)"
            else:
                message = f"{channel.name} (`{channel.id}`)"

        await self.send_log_message(Icons.hash_green, Colours.soft_green, title, message) 
开发者ID:python-discord,项目名称:bot,代码行数:26,代码来源:modlog.py

示例4: main_category

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def main_category(self) -> typing.Optional[discord.CategoryChannel]:
        if self.modmail_guild is not None:
            category_id = self.config["main_category_id"]
            if category_id is not None:
                try:
                    cat = discord.utils.get(self.modmail_guild.categories, id=int(category_id))
                    if cat is not None:
                        return cat
                except ValueError:
                    pass
                self.config.remove("main_category_id")
                logger.debug("MAIN_CATEGORY_ID was invalid, removed.")
            cat = discord.utils.get(self.modmail_guild.categories, name="Modmail")
            if cat is not None:
                self.config["main_category_id"] = cat.id
                logger.debug(
                    'No main category set explicitly, setting category "Modmail" as the main category.'
                )
                return cat
        return None 
开发者ID:kyb3r,项目名称:modmail,代码行数:22,代码来源:bot.py

示例5: get_category

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def get_category(cmd, guild):
    """
    Gets the temporary voice channel category for the server.
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param guild: The guild that triggered the event.
    :type guild: discord.Guild
    :return:
    :rtype: discord.CategoryChannel
    """
    custom_cat_id = await cmd.db.get_guild_settings(guild.id, 'temp_channel_category')
    custom_cat = guild.get_channel(custom_cat_id)
    if custom_cat:
        return custom_cat
    temp_cat = None
    cat_count = len(guild.categories)
    for category in guild.categories:
        if category.name.startswith('[Σ]'):
            temp_cat = category
            break
    if not temp_cat:
        cat_name = f'[Σ] {cmd.bot.user.name} Temp Channels'
        temp_cat = await guild.create_category_channel(name=cat_name, reason='Temp Channel Category')
        await temp_cat.edit(position=cat_count)
    return temp_cat 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:27,代码来源:temproom.py

示例6: slowmodecmd

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def slowmodecmd(self, ctx, delay: int = 0, channel: typing.Union[TextChannel, Category] = None):
        if not channel:
            channel = ctx.channel
        if isinstance(channel, discord.CategoryChannel):
            channels = channel.channels.copy()
            for c in channels:
                try:
                    await c.edit(slowmode_delay=delay)
                    channels.remove(c)
                except Exception:
                    pass
            if channels:
                return await ctx.error(f'Failed to set slowmode for {", ".join([c.name for c in channels])}')
            return await ctx.success(f'Successfully set slowmode for all channels in {channel}')
        try:
            await channel.edit(slowmode_delay=delay)
            return await ctx.success(f'Successfully set slowmode for {channel}')
        except Exception:
            return await ctx.error(f'Failed to set slowmode for {channel}') 
开发者ID:FireDiscordBot,项目名称:bot,代码行数:21,代码来源:slowmode.py

示例7: convert

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def convert(
        self, ctx: commands.Context, argument: str
    ) -> Union[discord.TextChannel, discord.CategoryChannel, discord.VoiceChannel]:
        match = self._get_id_match(argument) or re.match(r"<#([0-9]+)>$", argument)
        result = None
        guild = ctx.guild

        if match is None:
            # not a mention
            result = discord.utils.get(guild.channels, name=argument)

        else:
            channel_id = int(match.group(1))
            result = guild.get_channel(channel_id)

        if not result:
            raise BadArgument(f"Channel `{argument}` not found")
        return result 
开发者ID:TrustyJAID,项目名称:Trusty-cogs,代码行数:20,代码来源:converters.py

示例8: setup_auto_pickems

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def setup_auto_pickems(self, ctx, category: discord.CategoryChannel = None):
        """
            Sets up automatically created pickems channels every week.

            `[category]` the channel category where pickems channels will be created.
        """

        if category is None and not ctx.channel.category:
            return await ctx.send(_("A channel category is required."))
        elif category is None and ctx.channel.category is not None:
            category = ctx.channel.category
        else:
            pass
        if not category.permissions_for(ctx.me).manage_channels:
            await ctx.send(_("I don't have manage channels permission!"))
            return

        await self.config.guild(ctx.guild).pickems_category.set(category.id)
        async with self.pickems_save_lock:
            log.debug("Locking save")
            await Pickems.create_weekly_pickems_pages(self.bot, [ctx.guild], Game)
            # await self.initialize_pickems()
        await ctx.send(_("I will now automatically create pickems pages every Sunday.")) 
开发者ID:TrustyJAID,项目名称:Trusty-cogs,代码行数:25,代码来源:hockey.py

示例9: ignore

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def ignore(
        self,
        ctx: commands.Context,
        channel: Union[discord.TextChannel, discord.CategoryChannel, discord.VoiceChannel],
    ) -> None:
        """
            Ignore a channel from message delete/edit events and bot commands

            `channel` the channel or category to ignore events in
        """
        if ctx.guild.id not in self.settings:
            self.settings[ctx.guild.id] = inv_settings
        guild = ctx.message.guild
        if channel is None:
            channel = ctx.channel
        cur_ignored = await self.config.guild(guild).ignored_channels()
        if channel.id not in cur_ignored:
            cur_ignored.append(channel.id)
            await self.config.guild(guild).ignored_channels.set(cur_ignored)
            self.settings[guild.id]["ignored_channels"] = cur_ignored
            await ctx.send(_(" Now ignoring events in ") + channel.mention)
        else:
            await ctx.send(channel.mention + _(" is already being ignored.")) 
开发者ID:TrustyJAID,项目名称:Trusty-cogs,代码行数:25,代码来源:extendedmodlog.py

示例10: get_category_channels

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def get_category_channels(self, category: discord.CategoryChannel) -> t.Iterable[discord.TextChannel]:
        """Yield the text channels of the `category` in an unsorted manner."""
        log.trace(f"Getting text channels in the category '{category}' ({category.id}).")

        # This is faster than using category.channels because the latter sorts them.
        for channel in self.bot.get_guild(constants.Guild.id).channels:
            if channel.category_id == category.id and not self.is_excluded_channel(channel):
                yield channel 
开发者ID:python-discord,项目名称:bot,代码行数:10,代码来源:help_channels.py

示例11: init_categories

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def init_categories(self) -> None:
        """Get the help category objects. Remove the cog if retrieval fails."""
        log.trace("Getting the CategoryChannel objects for the help categories.")

        try:
            self.available_category = await self.try_get_channel(
                constants.Categories.help_available
            )
            self.in_use_category = await self.try_get_channel(constants.Categories.help_in_use)
            self.dormant_category = await self.try_get_channel(constants.Categories.help_dormant)
        except discord.HTTPException:
            log.exception("Failed to get a category; cog will be removed")
            self.bot.remove_cog(self.qualified_name) 
开发者ID:python-discord,项目名称:bot,代码行数:15,代码来源:help_channels.py

示例12: convert

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def convert(self, ctx, argument):
        bot = ctx.bot

        match = self._get_id_match(argument) or re.match(r'<#([0-9]+)>$', argument)
        result = None
        guild = ctx.guild

        if match is None:
            # not a mention
            if guild:
                result = discord.utils.get(guild.categories, name=argument)
            else:
                def check(c):
                    return isinstance(c, discord.CategoryChannel) and c.name == argument
                result = discord.utils.find(check, bot.get_all_channels())
        else:
            channel_id = int(match.group(1))
            if guild:
                result = guild.get_channel(channel_id)
            else:
                result = _get_from_guilds(bot, 'get_channel', channel_id)

        if not isinstance(result, discord.CategoryChannel):
            raise BadArgument('Channel "{}" not found.'.format(argument))

        return result 
开发者ID:Rapptz,项目名称:discord.py,代码行数:28,代码来源:converter.py

示例13: move

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def move(self, ctx, category: discord.CategoryChannel, *, specifics: str = None):
        """
        Move a thread to another category.

        `category` may be a category ID, mention, or name.
        `specifics` is a string which takes in arguments on how to perform the move. Ex: "silently"
        """
        thread = ctx.thread
        silent = False

        if specifics:
            silent_words = ["silent", "silently"]
            silent = any(word in silent_words for word in specifics.split())

        await thread.channel.edit(category=category, sync_permissions=True)

        if self.bot.config["thread_move_notify"] and not silent:
            embed = discord.Embed(
                title="Thread Moved",
                description=self.bot.config["thread_move_response"],
                color=self.bot.main_color,
            )
            await thread.recipient.send(embed=embed)

        sent_emoji, _ = await self.bot.retrieve_emoji()
        await self.bot.add_reaction(ctx.message, sent_emoji) 
开发者ID:kyb3r,项目名称:modmail,代码行数:28,代码来源:modmail.py

示例14: on_guild_channel_delete

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def on_guild_channel_delete(self, channel):
        if channel.guild != self.modmail_guild:
            return

        try:
            audit_logs = self.modmail_guild.audit_logs()
            entry = await audit_logs.find(lambda a: a.target == channel)
            mod = entry.user
        except AttributeError as e:
            # discord.py broken implementation with discord API
            # TODO: waiting for dpy
            logger.warning("Failed to retrieve audit log: %s.", e)
            return

        if mod == self.user:
            return

        if isinstance(channel, discord.CategoryChannel):
            if self.main_category == channel:
                logger.debug("Main category was deleted.")
                self.config.remove("main_category_id")
                await self.config.update()
            return

        if not isinstance(channel, discord.TextChannel):
            return

        if self.log_channel is None or self.log_channel == channel:
            logger.info("Log channel deleted.")
            self.config.remove("log_channel_id")
            await self.config.update()
            return

        thread = await self.threads.find(channel=channel)
        if thread and thread.channel == channel:
            logger.debug("Manually closed channel %s.", channel.name)
            await thread.close(closer=mod, silent=True, delete_channel=False) 
开发者ID:kyb3r,项目名称:modmail,代码行数:39,代码来源:bot.py

示例15: create

# 需要导入模块: import discord [as 别名]
# 或者: from discord import CategoryChannel [as 别名]
def create(
        self,
        recipient: typing.Union[discord.Member, discord.User],
        *,
        creator: typing.Union[discord.Member, discord.User] = None,
        category: discord.CategoryChannel = None,
    ) -> Thread:
        """Creates a Modmail thread"""

        # checks for existing thread in cache
        thread = self.cache.get(recipient.id)
        if thread:
            await thread.wait_until_ready()
            if thread.channel and self.bot.get_channel(thread.channel.id):
                logger.warning("Found an existing thread for %s, abort creating.", recipient)
                return thread
            logger.warning("Found an existing thread for %s, closing previous thread.", recipient)
            self.bot.loop.create_task(
                thread.close(closer=self.bot.user, silent=True, delete_channel=False)
            )

        thread = Thread(self, recipient)

        self.cache[recipient.id] = thread

        # Schedule thread setup for later
        cat = self.bot.main_category
        if category is None and len(cat.channels) == 50:
            fallback_id = self.bot.config["fallback_category_id"]
            if fallback_id:
                fallback = discord.utils.get(cat.guild.categories, id=int(fallback_id))
                if fallback and len(fallback.channels) != 50:
                    category = fallback

            if not category:
                category = await cat.clone(name="Fallback Modmail")
                self.bot.config.set("fallback_category_id", category.id)
                await self.bot.config.update()

        self.bot.loop.create_task(thread.setup(creator=creator, category=category))
        return thread 
开发者ID:kyb3r,项目名称:modmail,代码行数:43,代码来源:thread.py


注:本文中的discord.CategoryChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。