本文整理汇总了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)
示例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
)
示例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).
示例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()
示例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
示例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 < #
示例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>"))
示例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
示例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}}
)
示例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)
示例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
示例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
示例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
示例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
示例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))