当前位置: 首页>>代码示例>>Python>>正文


Python discord.DMChannel方法代码示例

本文整理汇总了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) 
开发者ID:python-discord,项目名称:bot,代码行数:27,代码来源:watchchannel.py

示例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() 
开发者ID:kyb3r,项目名称:modmail,代码行数:25,代码来源:bot.py

示例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) 
开发者ID:kyb3r,项目名称:modmail,代码行数:24,代码来源:bot.py

示例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 
开发者ID:kyb3r,项目名称:modmail,代码行数:23,代码来源:thread.py

示例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 
开发者ID:python-discord,项目名称:bot,代码行数:11,代码来源:helpers.py

示例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 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:4,代码来源:command.py

示例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.") 
开发者ID:avrae,项目名称:avrae,代码行数:10,代码来源:help.py

示例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) 
开发者ID:mdiller,项目名称:MangoByte,代码行数:33,代码来源:general.py

示例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) 
开发者ID:kenng69,项目名称:modmailbotkenng,代码行数:8,代码来源:bot.py

示例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 
开发者ID:kyb3r,项目名称:modmail,代码行数:31,代码来源:bot.py

示例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
        ) 
开发者ID:kyb3r,项目名称:modmail,代码行数:40,代码来源:clients.py

示例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) 
开发者ID:XiaomiFirmwareUpdater,项目名称:xiaomi_uranus_chatbot,代码行数:7,代码来源:subscriptions.py

示例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} 
开发者ID:XiaomiFirmwareUpdater,项目名称:xiaomi_uranus_chatbot,代码行数:16,代码来源:chat.py

示例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 
开发者ID:lehnification,项目名称:Discord-SelfBot,代码行数:13,代码来源:cmds.py

示例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))) 
开发者ID:lehnification,项目名称:Discord-SelfBot,代码行数:11,代码来源:selfbot.py


注:本文中的discord.DMChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。