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


Python discord.Guild方法代碼示例

本文整理匯總了Python中discord.Guild方法的典型用法代碼示例。如果您正苦於以下問題:Python discord.Guild方法的具體用法?Python discord.Guild怎麽用?Python discord.Guild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在discord的用法示例。


在下文中一共展示了discord.Guild方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_staff_channel_count

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def get_staff_channel_count(self, guild: Guild) -> int:
        """
        Get the number of channels that are staff-only.

        We need to know two things about a channel:
        - Does the @everyone role have explicit read deny permissions?
        - Do staff roles have explicit read allow permissions?

        If the answer to both of these questions is yes, it's a staff channel.
        """
        channel_ids = set()
        for channel in guild.channels:
            if channel.type is ChannelType.category:
                continue

            everyone_can_read = self.role_can_read(channel, guild.default_role)

            for role in constants.STAFF_ROLES:
                role_can_read = self.role_can_read(channel, guild.get_role(role))
                if role_can_read and not everyone_can_read:
                    channel_ids.add(channel.id)
                    break

        return len(channel_ids) 
開發者ID:python-discord,項目名稱:bot,代碼行數:26,代碼來源:information.py

示例2: on_member_unban

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def on_member_unban(self, guild: discord.Guild, member: discord.User) -> None:
        """Log member unban event to mod log."""
        if guild.id != GuildConstant.id:
            return

        if member.id in self._ignored[Event.member_unban]:
            self._ignored[Event.member_unban].remove(member.id)
            return

        member_str = escape_markdown(str(member))
        await self.send_log_message(
            Icons.user_unban, Colour.blurple(),
            "User unbanned", f"{member_str} (`{member.id}`)",
            thumbnail=member.avatar_url_as(static_format="png"),
            channel_id=Channels.mod_log
        ) 
開發者ID:python-discord,項目名稱:bot,代碼行數:18,代碼來源:modlog.py

示例3: _pardon_action

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def _pardon_action(self, infraction: utils.Infraction) -> t.Optional[t.Dict[str, str]]:
        """
        Execute deactivation steps specific to the infraction's type and return a log dict.

        If an infraction type is unsupported, return None instead.
        """
        guild = self.bot.get_guild(constants.Guild.id)
        user_id = infraction["user"]
        reason = f"Infraction #{infraction['id']} expired or was pardoned."

        if infraction["type"] == "mute":
            return await self.pardon_mute(user_id, guild, reason)
        elif infraction["type"] == "ban":
            return await self.pardon_ban(user_id, guild, reason)

    # endregion

    # This cannot be static (must have a __func__ attribute). 
開發者ID:python-discord,項目名稱:bot,代碼行數:20,代碼來源:infractions.py

示例4: on_guild_available

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def on_guild_available(self, guild: discord.Guild) -> None:
        """
        Set the internal guild available event when constants.Guild.id becomes available.

        If the cache appears to still be empty (no members, no channels, or no roles), the event
        will not be set.
        """
        if guild.id != constants.Guild.id:
            return

        if not guild.roles or not guild.members or not guild.channels:
            msg = "Guild available event was dispatched but the cache appears to still be empty!"
            log.warning(msg)

            try:
                webhook = await self.fetch_webhook(constants.Webhooks.dev_log)
            except discord.HTTPException as e:
                log.error(f"Failed to fetch webhook to send empty cache warning: status {e.status}")
            else:
                await webhook.send(f"<@&{constants.Roles.admin}> {msg}")

            return

        self._guild_available.set() 
開發者ID:python-discord,項目名稱:bot,代碼行數:26,代碼來源:bot.py

示例5: get_pref

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def get_pref(self, channel, pref):

        if isinstance(channel, discord.Guild):
            raise Exception("Guild used in place of channel")
        if channel in self._settings_cache.keys():
            return await self._settings_cache[channel][pref]

        await self.enable_channel(channel)

        # #self.bot.logger.debug(f"get_pref for {guild.id} pref {pref}")

        res = await self.request_json(self.channels_endpoint + f'{channel.id}/')
        self.bot.logger.debug(res)
        self._settings_cache[channel] = res
        value = res[pref]
        return value 
開發者ID:DuckHunt-discord,項目名稱:DHV3,代碼行數:18,代碼來源:data_store.py

示例6: set_pref

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def set_pref(self, channel, pref, value):
        if isinstance(channel, discord.Guild):
            raise Exception("Guild used in place of channel")
        if channel in self._settings_cache.keys():
            self._settings_cache.pop(channel)

        await self.ensure_channel_exist(channel)

        self.bot.logger.debug(f"-> (set_pref) {channel.id}, {pref}, {value}")
        headers = self.headers
        async with aiohttp.ClientSession() as cs:
            async with cs.patch(self.channels_endpoint + f'{channel.id}/', data={pref: value}, headers=headers) as r:
                res = (await r.json())[:75]
                self.bot.logger.debug(f"<- ({r.status}) {res}")

        await self.bot.log(level=2, title="Setting changed", message=f"{pref} now set to {value}", where=channel)

    # > Admins < # 
開發者ID:DuckHunt-discord,項目名稱:DHV3,代碼行數:20,代碼來源:data_store.py

示例7: on_guild_join

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def on_guild_join(self, guild: discord.Guild):
        _ = self.bot._

        for channel in guild.channels:
            if isinstance(channel, discord.TextChannel):
                if channel.permissions_for(guild.me).send_messages:
                    channel_used = channel
                    break

        else:
            return  # Nowhere to speak

        await self.bot.send_message(where=channel_used, message=_("Hello!\n "
                                                                  "Thanks for adding me in there! I'm almost ready to start the game!\n "
                                                                  "Could we please go into the channel where you want the game to be ? "
                                                                  "Please invoke me there by using `dh!setup`"
                                                                  "<:event_GuildAdded_01:439550913112309781>")) 
開發者ID:DuckHunt-discord,項目名稱:DHV3,代碼行數:19,代碼來源:setup_wizzard.py

示例8: modmail_guild

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def modmail_guild(self) -> typing.Optional[discord.Guild]:
        """
        The guild that the bot is operating in
        (where the bot is creating threads)
        """
        modmail_guild_id = self.config["modmail_guild_id"]
        if modmail_guild_id is None:
            return self.guild
        try:
            guild = discord.utils.get(self.guilds, id=int(modmail_guild_id))
            if guild is not None:
                return guild
        except ValueError:
            pass
        self.config.remove("modmail_guild_id")
        logger.critical("Invalid MODMAIL_GUILD_ID set.")
        return self.guild 
開發者ID:kyb3r,項目名稱:modmail,代碼行數:19,代碼來源:bot.py

示例9: update_data

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def update_data(db, data, user, guild):
    """
    Updates the static data of an interaction
    if the guild and member that submitted it are found.
    :param db: The main database handler reference.
    :type db: sigma.core.mechanics.database.Database
    :param data: The interaction data document.
    :type data: dict
    :param user: The user that submitted it.
    :type user: discord.Member
    :param guild: The guild that submitted it.
    :type guild: discord.Guild
    """
    if user:
        unam = data.get('user_name')
        if unam is None or unam != user.name:
            await db[db.db_nam].Interactions.update_many(
                {'user_id': data.get('user_id')}, {'$set': {'user_name': user.name}}
            )
    if guild:
        snam = data.get('server_name')
        if snam is None or snam != guild.name:
            await db[db.db_nam].Interactions.update_many(
                {'server_id': data.get('server_id')}, {'$set': {'server_name': guild.name}}
            ) 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:27,代碼來源:interaction_mechanics.py

示例10: leave_move_log

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def leave_move_log(ev, pld):
    """
    :param ev: The event object referenced in the event.
    :type ev: sigma.core.mechanics.event.SigmaEvent
    :param pld: The event payload data to process.
    :type pld: sigma.core.mechanics.payload.GuildPayload
    """
    owner = pld.guild.owner
    bot_count = 0
    user_count = 0
    for user in pld.guild.members:
        if user.bot:
            bot_count += 1
        else:
            user_count += 1
    log_lines = f'Guild: {pld.guild.name} [{pld.guild.id}] | '
    log_lines += f'Owner: {owner.name} [{owner.id}] | '
    log_lines += f'Members: {user_count} | Bots: {bot_count}'
    ev.log.info(log_lines)
    if ev.bot.cfg.pref.movelog_channel:
        move_data = make_move_log_data(pld.guild, False, user_count, bot_count)
        await ev.db[ev.db.db_nam].Movements.insert_one(move_data) 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:24,代碼來源:leave_move_log.py

示例11: check_perm_validity

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def check_perm_validity(gld: discord.Guild, requested: list):
    """

    :param gld:
    :type gld:
    :param requested:
    :type requested:
    :return:
    :rtype:
    """
    invalid_perms = []
    for req in requested:
        valid = False
        for perm in gld.roles[0].permissions:
            if perm[0].replace('_', ' ').lower() == req.lower():
                valid = True
                break
        if not valid:
            invalid_perms.append(req)
    return invalid_perms 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:22,代碼來源:roleswithpermission.py

示例12: get_matching_emote

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def get_matching_emote(guild, emote):
    """
    Gets a matching emote from the given guild.
    :param guild: The guild to search.
    :type guild: discord.Guild
    :param emote: The full emote string to look for.
    :type emote: str
    :return:
    :rtype: discord.Emoji
    """
    emote_name = emote.split(':')[1]
    matching_emote = None
    for emote in guild.emojis:
        if emote.name == emote_name:
            matching_emote = emote
    return matching_emote 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:18,代碼來源:raffleicon.py

示例13: make_greet_embed

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def make_greet_embed(data: dict, greeting: str, guild: discord.Guild):
    """

    :param data:
    :type data:
    :param greeting:
    :type greeting:
    :param guild:
    :type guild:
    :return:
    :rtype:
    """
    guild_icon = str(guild.icon_url) if guild.icon_url else discord.Embed.Empty
    guild_color = await get_image_colors(guild_icon)
    greeting = discord.Embed(color=data.get('color') or guild_color, description=greeting)
    greeting.set_author(name=guild.name, icon_url=guild_icon)
    if data.get('thumbnail'):
        greeting.set_thumbnail(url=data.get('thumbnail'))
    if data.get('image'):
        greeting.set_image(url=data.get('image'))
    return greeting 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:23,代碼來源:greetmessage.py

示例14: make_bye_embed

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def make_bye_embed(data: dict, goodbye: str, guild: discord.Guild):
    """

    :param data:
    :type data:
    :param goodbye:
    :type goodbye:
    :param guild:
    :type guild:
    :return:
    :rtype:
    """
    guild_icon = str(guild.icon_url) if guild.icon_url else discord.Embed.Empty
    guild_color = await get_image_colors(guild_icon)
    goodbye = discord.Embed(color=data.get('color') or guild_color, description=goodbye)
    goodbye.set_author(name=guild.name, icon_url=guild_icon)
    if data.get('thumbnail'):
        goodbye.set_thumbnail(url=data.get('thumbnail'))
    if data.get('image'):
        goodbye.set_image(url=data.get('image'))
    return goodbye 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:23,代碼來源:byemessage.py

示例15: make_incident

# 需要導入模塊: import discord [as 別名]
# 或者: from discord import Guild [as 別名]
def make_incident(db: Database, gld: discord.Guild, ath: discord.Member, trg: discord.Member):
    """

    :param db:
    :type db:
    :param gld:
    :type gld:
    :param ath:
    :type ath:
    :param trg:
    :type trg:
    """
    icore = get_incident_core(db)
    inc = icore.generate('unwarn')
    inc.set_location(gld)
    inc.set_moderator(ath)
    inc.set_target(trg)
    await icore.save(inc)
    await icore.report(gld, inc.to_embed('⚠', 0xFFCC4D)) 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:21,代碼來源:removewarning.py


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