當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。