繁体   English   中英

您可以将其转换为嵌入吗? discord.py

[英]Can you convert this to an embed? discord.py

此代码有效,我只是希望将其转换为嵌入,如果您不打算提供帮助,请不要编辑它以破坏它。

import discord, asyncio
from discord.ext import commands

class MyCog(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def dm(self, ctx, user_id: int, *, message: str):
        """ DM the user of your choice """
        await ctx.message.delete()
        user = self.bot.get_user(user_id)
        if not user:
            return await ctx.send(f"Could not find any UserID matching **{user_id}**")

        try:
           await user.send(message + f"\nMessage Sent By <@{ctx.author.id}>\n{ctx.author.name}{ctx.author.discriminator}")
           await ctx.send(f"✉️ Sent a DM to {user.name + '#' + user.discriminator}")
        except discord.Forbidden:
            await ctx.send("This user might be having DMs blocked or it's a bot account...")

此代码有效,只需要嵌入即可。

如果您可以提供帮助,请提供帮助,否则请勿将其编辑为“修复”它,而实际上您只是在破坏它。

要进行嵌入,请使用discord.Embed

import discord, asyncio
from discord.ext import commands

class MyCog(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def dm(self, ctx, user_id: int = None, *, message: str = None):
        """DMs the user of your choice."""
        try:
            await ctx.message.delete()
        except: # If it fails to delete the invocation message
            pass

        user = self.bot.get_user(user_id)
        if not user:
            await ctx.send(f"Could not find any UserID matching **{user_id}**")
            return

        embed = discord.Embed(title="New message", description=message)
        embed.set_footer(text="Message Sent By " + str(ctx.author), icon_url=ctx.author.avatar_url)
    
        try:
            await user.send(embed=embed)
            await ctx.send("✉️ Sent a DM to " + str(user))
        except discord.Forbidden:
            await ctx.send("This user might be having DMs blocked or it's a bot account...")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM