Python discord.CategoryChannel() Examples
The following are 22
code examples of discord.CategoryChannel().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
discord
, or try the search function
.
Example #1
Source File: modlog.py From bot with MIT License | 7 votes |
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 )
Example #2
Source File: help_channels.py From bot with MIT License | 7 votes |
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())
Example #3
Source File: extendedmodlog.py From Trusty-cogs with MIT License | 6 votes |
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."))
Example #4
Source File: hockey.py From Trusty-cogs with MIT License | 6 votes |
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."))
Example #5
Source File: modlog.py From bot with MIT License | 6 votes |
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)
Example #6
Source File: converters.py From Trusty-cogs with MIT License | 6 votes |
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
Example #7
Source File: bot.py From modmail with GNU Affero General Public License v3.0 | 6 votes |
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
Example #8
Source File: slowmode.py From bot with MIT License | 6 votes |
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}')
Example #9
Source File: temproom.py From apex-sigma-core with GNU General Public License v3.0 | 6 votes |
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
Example #10
Source File: tempcategory.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def tempcategory(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 """ if pld.msg.author.permissions_in(pld.msg.channel).manage_channels: if pld.args: if pld.args[0].lower() == 'disable': await cmd.db.set_guild_settings(pld.msg.guild.id, 'temp_channel_category', None) response = ok('Temp Channel Category disabled.') await pld.msg.channel.send(embed=response) return target = None lookup = ' '.join(pld.args).lower() if lookup.isdigit(): try: search = pld.msg.guild.get_channel(int(lookup)) if isinstance(search, discord.CategoryChannel): target = search except ValueError: target = None else: target = discord.utils.find(lambda c: c.name.lower() == lookup, pld.msg.guild.categories) if target: if pld.msg.guild.me.permissions_in(target).manage_channels: await cmd.db.set_guild_settings(pld.msg.guild.id, 'temp_channel_category', target.id) response = ok(f'Temp Channel Category set to {target.name}') else: response = error('I can\'t create channels in that category.') else: response = not_found('Category not found.') else: response = error('Nothing inputted.') else: response = denied('Access Denied. Manage Channels needed.') await pld.msg.channel.send(embed=response)
Example #11
Source File: hockey.py From Trusty-cogs with MIT License | 5 votes |
def gdc_setup( self, ctx, team: HockeyTeams, category: discord.CategoryChannel = None, delete_gdc: bool = True, ): """ Setup game day channels for a single team or all teams Required parameters: `team` must use quotes if a space is in the name will search for partial team name Optional Parameters: `category` must use quotes if a space is in the name will default to current category `delete_gdc` will tell the bot whether or not to delete game day channels automatically must be either `True` or `False` and a category must be provided """ guild = ctx.message.guild if category is None and ctx.channel.category is not None: category = guild.get_channel(ctx.channel.category_id) else: return await ctx.send( _("You must specify a channel category for game day channels to be created under.") ) if not category.permissions_for(guild.me).manage_channels: await ctx.send(_("I don't have manage channels permission!")) return await self.config.guild(guild).category.set(category.id) await self.config.guild(guild).gdc_team.set(team) await self.config.guild(guild).delete_gdc.set(delete_gdc) await self.config.guild(guild).create_channels.set(True) if team.lower() != "all": await GameDayChannels.create_gdc(self.bot, guild) else: game_list = await Game.get_games() for game in game_list: await GameDayChannels.create_gdc(self.bot, guild, game) await ctx.send(_("Game Day Channels for ") + team + _("setup in ") + category.name) ####################################################################### # All Hockey setup commands
Example #12
Source File: hockey.py From Trusty-cogs with MIT License | 5 votes |
def gdc_category(self, ctx, category: discord.CategoryChannel): """ Change the category for channel creation. Channel is case sensitive. """ guild = ctx.message.guild # cur_setting = await self.config.guild(guild).category() msg = _("Game day channels will be created in ") await self.config.guild(guild).category.set(category.id) await ctx.send(msg + category.name)
Example #13
Source File: utils.py From bot with MIT License | 5 votes |
def getperms(self, member: discord.Member, channel: typing.Union[discord.TextChannel, discord.VoiceChannel, discord.CategoryChannel]): perms = [] for perm, value in member.permissions_in(channel): if value: perms.append(perm) return perms
Example #14
Source File: hardunmute.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def hardunmute(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 """ if pld.msg.author.permissions_in(pld.msg.channel).manage_channels: target = get_broad_target(pld) if target: hierarchy_me = hierarchy_permit(pld.msg.guild.me, target) if hierarchy_me: hierarchy_auth = hierarchy_permit(pld.msg.author, target) if hierarchy_auth: reason = ' '.join(pld.args[1:]) if pld.args[1:] else None await make_incident(cmd.db, pld.msg.guild, pld.msg.author, target, reason) ongoing = discord.Embed(color=0x696969, title='⛓ Editing permissions...') ongoing_msg = await pld.msg.channel.send(embed=ongoing) for channel in pld.msg.guild.channels: if isinstance(channel, discord.TextChannel) or isinstance(channel, discord.CategoryChannel): try: # noinspection PyTypeChecker await channel.set_permissions(target, overwrite=None, reason=reason) except discord.Forbidden: pass log_embed = generate_log_embed(pld.msg, target, reason) await log_event(cmd.bot, pld.settings, log_embed, 'log_mutes') response = ok(f'{target.display_name} has been hard-unmuted.') await ongoing_msg.delete() else: response = error('That user is equal or above you.') else: response = error('I can\'t mute a user equal or above me.') else: response = error('No user targeted.') else: response = denied('Access Denied. Manage Channels needed.') await pld.msg.channel.send(embed=response)
Example #15
Source File: thread.py From modmail with GNU Affero General Public License v3.0 | 5 votes |
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
Example #16
Source File: bot.py From modmail with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #17
Source File: modmail.py From modmail with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #18
Source File: converter.py From discord.py with MIT License | 5 votes |
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
Example #19
Source File: help_channels.py From bot with MIT License | 5 votes |
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)
Example #20
Source File: help_channels.py From bot with MIT License | 5 votes |
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
Example #21
Source File: game.py From Fox-V3 with GNU Affero General Public License v3.0 | 4 votes |
def __init__(self, guild: discord.Guild, role: discord.Role = None, category: discord.CategoryChannel = None, village: discord.TextChannel = None, log_channel: discord.TextChannel = None, game_code=None): self.guild = guild self.game_code = game_code self.roles = [] # List[Role] self.players = [] # List[Player] self.day_vote = {} # author: target self.vote_totals = {} # id: total_votes self.started = False self.game_over = False self.can_vote = False self.used_votes = 0 self.day_time = False self.day_count = 0 self.ongoing_vote = False self.game_role = role # discord.Role self.channel_category = category # discord.CategoryChannel self.village_channel = village # discord.TextChannel self.log_channel = log_channel self.to_delete = set() self.save_perms = {} self.p_channels = {} # uses default_secret_channel self.vote_groups = {} # ID : VoteGroup() self.night_results = [] self.loop = asyncio.get_event_loop() # def __del__(self): # """ # Cleanup channels as necessary # :return: # """ # # print("Delete is called") # # self.game_over = True # if self.village_channel: # asyncio.ensure_future(self.village_channel.delete("Werewolf game-over")) # # for c_data in self.p_channels.values(): # asyncio.ensure_future(c_data["channel"].delete("Werewolf game-over"))
Example #22
Source File: modmail.py From modmail with GNU Affero General Public License v3.0 | 4 votes |
def contact( self, ctx, user: Union[discord.Member, discord.User], *, category: discord.CategoryChannel = None, ): """ Create a thread with a specified member. If `category` is specified, the thread will be created in that specified category. `category`, if specified, may be a category ID, mention, or name. `user` may be a user ID, mention, or name. """ if user.bot: embed = discord.Embed( color=self.bot.error_color, description="Cannot start a thread with a bot." ) return await ctx.send(embed=embed) exists = await self.bot.threads.find(recipient=user) if exists: embed = discord.Embed( color=self.bot.error_color, description="A thread for this user already " f"exists in {exists.channel.mention}.", ) await ctx.channel.send(embed=embed) else: thread = await self.bot.threads.create(user, creator=ctx.author, category=category) if self.bot.config["dm_disabled"] >= 1: logger.info("Contacting user %s when Modmail DM is disabled.", user) embed = discord.Embed( title="Created Thread", description=f"Thread started by {ctx.author.mention} for {user.mention}.", color=self.bot.main_color, ) await thread.wait_until_ready() await thread.channel.send(embed=embed) sent_emoji, _ = await self.bot.retrieve_emoji() await self.bot.add_reaction(ctx.message, sent_emoji) await asyncio.sleep(3) await ctx.message.delete()