本文整理汇总了Python中discord.Member方法的典型用法代码示例。如果您正苦于以下问题:Python discord.Member方法的具体用法?Python discord.Member怎么用?Python discord.Member使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.Member方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: revoke_send_permissions
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def revoke_send_permissions(self, member: discord.Member) -> None:
"""
Disallow `member` to send messages in the Available category for a certain time.
The time until permissions are reinstated can be configured with
`HelpChannels.claim_minutes`.
"""
log.trace(
f"Revoking {member}'s ({member.id}) send message permissions in the Available category."
)
await self.add_cooldown_role(member)
# Cancel the existing task, if any.
# Would mean the user somehow bypassed the lack of permissions (e.g. user is guild owner).
self.cancel_task(member.id, ignore_missing=True)
await self.schedule_cooldown_expiration(member, constants.HelpChannels.claim_minutes * 60)
示例2: add
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def add(self, rule_name: str, members: Iterable[Member], messages: Iterable[Message]) -> None:
"""Adds new rule violation events to the deletion context."""
self.rules.add(rule_name)
for member in members:
if member.id not in self.members:
self.members[member.id] = member
for message in messages:
if message.id not in self.messages:
self.messages[message.id] = message
# Re-upload attachments
destination = message.guild.get_channel(Channels.attachment_log)
urls = await send_attachments(message, destination, link_large=False)
self.attachments.append(urls)
示例3: punish
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def punish(self, msg: Message, member: Member, reason: str) -> None:
"""Punishes the given member for triggering an antispam rule."""
if not any(role.id == self.muted_role.id for role in member.roles):
remove_role_after = AntiSpamConfig.punishment['remove_after']
# Get context and make sure the bot becomes the actor of infraction by patching the `author` attributes
context = await self.bot.get_context(msg)
context.author = self.bot.user
context.message.author = self.bot.user
# Since we're going to invoke the tempmute command directly, we need to manually call the converter.
dt_remove_role_after = await self.expiration_date_converter.convert(context, f"{remove_role_after}S")
await context.invoke(
self.bot.get_command('tempmute'),
member,
dt_remove_role_after,
reason=reason
)
示例4: _change_cooldown_role
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def _change_cooldown_role(self, member: discord.Member, coro_func: CoroutineFunc) -> None:
"""
Change `member`'s cooldown role via awaiting `coro_func` and handle errors.
`coro_func` is intended to be `discord.Member.add_roles` or `discord.Member.remove_roles`.
"""
guild = self.bot.get_guild(constants.Guild.id)
role = guild.get_role(constants.Roles.help_cooldown)
if role is None:
log.warning(f"Help cooldown role ({constants.Roles.help_cooldown}) could not be found!")
return
try:
await coro_func(role)
except discord.NotFound:
log.debug(f"Failed to change role for {member} ({member.id}): member not found")
except discord.Forbidden:
log.debug(
f"Forbidden to change role for {member} ({member.id}); "
f"possibly due to role hierarchy"
)
except discord.HTTPException as e:
log.error(f"Failed to change role for {member} ({member.id}): {e.status} {e.code}")
示例5: send_defcon_log
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def send_defcon_log(self, action: Action, actor: Member, e: Exception = None) -> None:
"""Send log message for DEFCON action."""
info = action.value
log_msg: str = (
f"**Staffer:** {actor.mention} {actor} (`{actor.id}`)\n"
f"{info.template.format(days=self.days.days)}"
)
status_msg = f"DEFCON {action.name.lower()}"
if e:
log_msg += (
"**There was a problem updating the site** - This setting may be reverted when the bot restarts.\n\n"
f"```py\n{e}\n```"
)
await self.mod_log.send_log_message(info.icon, info.color, status_msg, log_msg)
示例6: user_info
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def user_info(self, ctx: Context, user: Member = None) -> None:
"""Returns info about a user."""
if user is None:
user = ctx.author
# Do a role check if this is being executed on someone other than the caller
elif user != ctx.author and not with_role_check(ctx, *constants.MODERATION_ROLES):
await ctx.send("You may not use this command on users other than yourself.")
return
# Non-staff may only do this in #bot-commands
if not with_role_check(ctx, *constants.STAFF_ROLES):
if not ctx.channel.id == constants.Channels.bot_commands:
raise InWhitelistCheckFailure(constants.Channels.bot_commands)
embed = await self.create_user_embed(ctx, user)
await ctx.send(embed=embed)
示例7: basic_user_infraction_counts
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def basic_user_infraction_counts(self, member: Member) -> str:
"""Gets the total and active infraction counts for the given `member`."""
infractions = await self.bot.api_client.get(
'bot/infractions',
params={
'hidden': 'False',
'user__id': str(member.id)
}
)
total_infractions = len(infractions)
active_infractions = sum(infraction['active'] for infraction in infractions)
infraction_output = f"**Infractions**\nTotal: {total_infractions}\nActive: {active_infractions}"
return infraction_output
示例8: user_nomination_counts
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def user_nomination_counts(self, member: Member) -> str:
"""Gets the active and historical nomination counts for the given `member`."""
nominations = await self.bot.api_client.get(
'bot/nominations',
params={
'user__id': str(member.id)
}
)
output = ["**Nominations**"]
if not nominations:
output.append("This user has never been nominated.")
else:
count = len(nominations)
is_currently_nominated = any(nomination["active"] for nomination in nominations)
nomination_noun = "nomination" if count == 1 else "nominations"
if is_currently_nominated:
output.append(f"This user is **currently** nominated ({count} {nomination_noun} in total).")
else:
output.append(f"This user has {count} historical {nomination_noun}, but is currently not nominated.")
return "\n".join(output)
示例9: on_member_join
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def on_member_join(self, member: discord.Member) -> None:
"""Log member join event to user log."""
if member.guild.id != GuildConstant.id:
return
member_str = escape_markdown(str(member))
message = f"{member_str} (`{member.id}`)"
now = datetime.utcnow()
difference = abs(relativedelta(now, member.created_at))
message += "\n\n**Account age:** " + humanize_delta(difference)
if difference.days < 1 and difference.months < 1 and difference.years < 1: # New user account!
message = f"{Emojis.new} {message}"
await self.send_log_message(
Icons.sign_in, Colours.soft_green,
"User joined", message,
thumbnail=member.avatar_url_as(static_format="png"),
channel_id=Channels.user_log
)
示例10: on_member_remove
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def on_member_remove(self, member: discord.Member) -> None:
"""Log member leave event to user log."""
if member.guild.id != GuildConstant.id:
return
if member.id in self._ignored[Event.member_remove]:
self._ignored[Event.member_remove].remove(member.id)
return
member_str = escape_markdown(str(member))
await self.send_log_message(
Icons.sign_out, Colours.soft_red,
"User left", f"{member_str} (`{member.id}`)",
thumbnail=member.avatar_url_as(static_format="png"),
channel_id=Channels.user_log
)
示例11: on_member_join
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def on_member_join(self, member: Member) -> None:
"""Reapply active mute infractions for returning members."""
active_mutes = await self.bot.api_client.get(
"bot/infractions",
params={
"active": "true",
"type": "mute",
"user__id": member.id
}
)
if active_mutes:
reason = f"Re-applying active mute: {active_mutes[0]['id']}"
action = member.add_roles(self._muted_role, reason=reason)
await self.reapply_infraction(active_mutes[0], action)
# region: Permanent infractions
示例12: shadow_tempmute
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def shadow_tempmute(
self, ctx: Context,
user: Member,
duration: Expiry,
*,
reason: t.Optional[str] = None
) -> None:
"""
Temporarily mute a user for the given reason and duration without notifying the user.
A unit of time should be appended to the duration.
Units (∗case-sensitive):
\u2003`y` - years
\u2003`m` - months∗
\u2003`w` - weeks
\u2003`d` - days
\u2003`h` - hours
\u2003`M` - minutes∗
\u2003`s` - seconds
Alternatively, an ISO 8601 timestamp can be provided for the duration.
"""
await self.apply_mute(ctx, user, reason, expires_at=duration, hidden=True)
示例13: apply_mute
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def apply_mute(self, ctx: Context, user: Member, reason: t.Optional[str], **kwargs) -> None:
"""Apply a mute infraction with kwargs passed to `post_infraction`."""
if await utils.get_active_infraction(ctx, user, "mute"):
return
infraction = await utils.post_infraction(ctx, user, "mute", reason, active=True, **kwargs)
if infraction is None:
return
self.mod_log.ignore(Event.member_update, user.id)
async def action() -> None:
await user.add_roles(self._muted_role, reason=reason)
log.trace(f"Attempting to kick {user} from voice because they've been muted.")
await user.move_to(None, reason=reason)
await self.apply_infraction(ctx, infraction, user, action())
示例14: pardon_mute
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def pardon_mute(self, user_id: int, guild: discord.Guild, reason: t.Optional[str]) -> t.Dict[str, str]:
"""Remove a user's muted role, DM them a notification, and return a log dict."""
user = guild.get_member(user_id)
log_text = {}
if user:
# Remove the muted role.
self.mod_log.ignore(Event.member_update, user.id)
await user.remove_roles(self._muted_role, reason=reason)
# DM the user about the expiration.
notified = await utils.notify_pardon(
user=user,
title="You have been unmuted",
content="You may now send messages in the server.",
icon_url=utils.INFRACTION_ICONS["mute"][1]
)
log_text["Member"] = f"{user.mention}(`{user.id}`)"
log_text["DM"] = "Sent" if notified else "**Failed**"
else:
log.info(f"Failed to unmute user {user_id}: user not found")
log_text["Failure"] = "User was not found in the guild."
return log_text
示例15: proxy_user
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Member [as 别名]
def proxy_user(user_id: str) -> discord.Object:
"""
Create a proxy user object from the given id.
Used when a Member or User object cannot be resolved.
"""
log.trace(f"Attempting to create a proxy user for the user id {user_id}.")
try:
user_id = int(user_id)
except ValueError:
log.debug(f"Failed to create proxy user {user_id}: could not convert to int.")
raise BadArgument(f"User ID `{user_id}` is invalid - could not convert to an integer.")
user = discord.Object(user_id)
user.mention = user.id
user.display_name = f"<@{user.id}>"
user.avatar_url_as = lambda static_format: None
user.bot = False
return user