本文整理汇总了Python中discord.DMChannel方法的典型用法代码示例。如果您正苦于以下问题:Python discord.DMChannel方法的具体用法?Python discord.DMChannel怎么用?Python discord.DMChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.DMChannel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_header
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def send_header(self, msg: Message) -> None:
"""Sends a header embed with information about the relayed messages to the watch channel."""
user_id = msg.author.id
guild = self.bot.get_guild(GuildConfig.id)
actor = guild.get_member(self.watched_users[user_id]['actor'])
actor = actor.display_name if actor else self.watched_users[user_id]['actor']
inserted_at = self.watched_users[user_id]['inserted_at']
time_delta = self._get_time_delta(inserted_at)
reason = self.watched_users[user_id]['reason']
if isinstance(msg.channel, DMChannel):
# If a watched user DMs the bot there won't be a channel name or jump URL
# This could technically include a GroupChannel but bot's can't be in those
message_jump = "via DM"
else:
message_jump = f"in [#{msg.channel.name}]({msg.jump_url})"
footer = f"Added {time_delta} by {actor} | Reason: {reason}"
embed = Embed(description=f"{msg.author.mention} {message_jump}")
embed.set_footer(text=textwrap.shorten(footer, width=128, placeholder="..."))
await self.webhook_send(embed=embed, username=msg.author.display_name, avatar_url=msg.author.avatar_url)
示例2: on_typing
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def on_typing(self, channel, user, _):
await self.wait_for_connected()
if user.bot:
return
if isinstance(channel, discord.DMChannel):
if not self.config.get("user_typing"):
return
thread = await self.threads.find(recipient=user)
if thread:
await thread.channel.trigger_typing()
else:
if not self.config.get("mod_typing"):
return
thread = await self.threads.find(channel=channel)
if thread is not None and thread.recipient:
if await self.is_blocked(thread.recipient):
return
await thread.recipient.trigger_typing()
示例3: on_message_edit
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def on_message_edit(self, before, after):
if after.author.bot:
return
if before.content == after.content:
return
if isinstance(after.channel, discord.DMChannel):
thread = await self.threads.find(recipient=before.author)
if not thread:
return
try:
await thread.edit_dm_message(after, after.content)
except ValueError:
_, blocked_emoji = await self.retrieve_emoji()
await self.add_reaction(after, blocked_emoji)
else:
embed = discord.Embed(
description="Successfully Edited Message", color=self.main_color
)
embed.set_footer(text=f"Message ID: {after.id}")
await after.channel.send(embed=embed)
示例4: __init__
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def __init__(
self,
manager: "ThreadManager",
recipient: typing.Union[discord.Member, discord.User, int],
channel: typing.Union[discord.DMChannel, discord.TextChannel] = None,
):
self.manager = manager
self.bot = manager.bot
if isinstance(recipient, int):
self._id = recipient
self._recipient = None
else:
if recipient.bot:
raise CommandError("Recipient cannot be a bot.")
self._id = recipient.id
self._recipient = recipient
self._channel = channel
self.genesis_message = None
self._ready_event = asyncio.Event()
self.close_task = None
self.auto_close_task = None
示例5: __init__
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def __init__(self, **kwargs) -> None:
default_kwargs = {'id': next(self.discord_id), 'name': 'channel', 'guild': MockGuild()}
super().__init__(**collections.ChainMap(kwargs, default_kwargs))
if 'mention' not in kwargs:
self.mention = f"#{self.name}"
# Create data for the DMChannel instance
示例6: guild_or_channel_id
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def guild_or_channel_id(channel: Union[TextChannel, DMChannel, GroupChannel]) -> int:
return getattr(channel, 'guild', channel).id
示例7: send
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def send(self):
"""A helper utility to send the page output from :attr:`paginator` to the destination."""
destination = self.get_destination()
for embed in self.embed_paginator.embeds:
await destination.send(embed=embed)
if not isinstance(self.context.channel, discord.DMChannel) and self.in_dms:
await self.context.channel.send("I have sent help to your PMs.")
示例8: wiki
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def wiki(self, ctx, *, thing : str):
"""Looks up a thing on wikipedia
Uses my own implementation of the [Wikipedia API](https://www.mediawiki.org/wiki/API:Tutorial)
You can also try `{cmdpfx} wiki random` to get a random wiki page
Note that I've had to remove the images from these (unless you're in a NSFW channel) because I have no way of checking if it is an NSFW image, and posting an NSFW image in non-NSFW channels would be against discord's ToS. Sorry about that!
**Example:**
`{cmdpfx}wiki potato`
"""
await ctx.channel.trigger_typing()
page = await wikipedia.get_wikipedia_page(thing)
embed = discord.Embed(description=page.markdown)
embed.title = f"**{page.title}**"
embed.url = page.url
footer_text = "Retrieved from Wikipedia"
if page.image:
if (not isinstance(ctx.channel, discord.DMChannel)) and ctx.channel.is_nsfw():
embed.set_image(url=page.image)
else:
footer_text += ". (Image omitted because I can't check if it is NSFW) D:"
embed.set_footer(text=footer_text, icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Wikipedia's_W.svg/2000px-Wikipedia's_W.svg.png")
await ctx.send(embed=embed)
示例9: on_message
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def on_message(self, message):
if message.author.bot:
return
await self.process_commands(message)
if isinstance(message.channel, discord.DMChannel):
await self.process_modmail(message)
示例10: on_message_delete
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def on_message_delete(self, message):
"""Support for deleting linked messages"""
# TODO: use audit log to check if modmail deleted the message
if isinstance(message.channel, discord.DMChannel):
thread = await self.threads.find(recipient=message.author)
if not thread:
return
try:
message = await thread.find_linked_message_from_dm(message)
except ValueError as e:
if str(e) != "Thread channel message not found.":
logger.warning("Failed to find linked message to delete: %s", e)
return
embed = message.embeds[0]
embed.set_footer(text=f"{embed.footer.text} (deleted)", icon_url=embed.footer.icon_url)
await message.edit(embed=embed)
return
thread = await self.threads.find(channel=message.channel)
if not thread:
return
try:
await thread.delete_message(message, note=False)
except ValueError as e:
if str(e) not in {"DM message not found.", "Malformed thread message."}:
logger.warning("Failed to find linked message to delete: %s", e)
return
except discord.NotFound:
return
示例11: append_log
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def append_log(
self,
message: Message,
*,
message_id: str = "",
channel_id: str = "",
type_: str = "thread_message",
) -> dict:
channel_id = str(channel_id) or str(message.channel.id)
message_id = str(message_id) or str(message.id)
data = {
"timestamp": str(message.created_at),
"message_id": message_id,
"author": {
"id": str(message.author.id),
"name": message.author.name,
"discriminator": message.author.discriminator,
"avatar_url": str(message.author.avatar_url),
"mod": not isinstance(message.channel, DMChannel),
},
"content": message.content,
"type": type_,
"attachments": [
{
"id": a.id,
"filename": a.filename,
"is_image": a.width is not None,
"size": a.size,
"url": a.url,
}
for a in message.attachments
],
}
return await self.logs.find_one_and_update(
{"channel_id": channel_id}, {"$push": {"messages": data}}, return_document=True
)
示例12: subscription_allowed
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def subscription_allowed(message) -> bool:
"""Check if the subscription is allowed"""
return bool(isinstance(message.channel, DMChannel)
or message.author.guild_permissions.administrator
or message.author.id in DISCORD_BOT_ADMINS)
示例13: get_chat_info
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def get_chat_info(message) -> dict:
"""Returns a dictionary of user information"""
if isinstance(message.channel, DMChannel):
chat_type = "user"
name = message.channel.recipient.name
guild_id = None
guild_name = None
else:
chat_type = "channel"
name = message.channel.name
guild_id = message.guild.id
guild_name = message.guild.name
return {'id': message.channel.id, 'name': name,'type': chat_type,
'guild_id': guild_id, 'guild_name': guild_name}
示例14: log_command
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def log_command(self, ctx, command):
self.bot.commands_triggered[command] += 1
if isinstance(ctx.channel, discord.DMChannel):
destination = f'PM with {ctx.channel.recipient}'
elif isinstance(ctx.channel, discord.GroupChannel):
destination = f'Group {ctx.channel}'
else:
destination = f'#{ctx.channel.name},({ctx.guild.name})'
log.info(f'In {destination}: {command}')
# Cumstom Commands with prefix
示例15: before_invoke
# 需要导入模块: import discord [as 别名]
# 或者: from discord import DMChannel [as 别名]
def before_invoke(ctx):
bot.commands_triggered[ctx.command.qualified_name] += 1
if isinstance(ctx.channel, discord.DMChannel):
destination = f'PM with {ctx.channel.recipient}'
elif isinstance(ctx.channel, discord.GroupChannel):
destination = f'Group {ctx.channel}'
else:
destination = f'#{ctx.channel.name},({ctx.guild.name})'
log.info('In {}: {}'.format(destination, ctx.message.content.strip(ctx.prefix)))