0
votes

I try to make a function that will take text and channel_id params and send a embed to specific channel. For some reason, bot is not sending anything to the channel. What did I wrong?

async def QuickEmbed(text, channelId):
    channel = bot.get_channel(channelId)
    em = discord.Embed(title="\u200b", description=text, color="#f1c40f")
    await channel.send(embed=em)

@bot.command()
async def log(ctx):
    await QuickEmbed("test message", 123456789)```
1
Do you use a real channel id in your code?Nurqm
Yes. I changed it in this post to a fake one.XPOLKYT STUDIOS
Doesn't it send anything or just sends hello?Nurqm
sorry, .send() was supposed to contain embed=emXPOLKYT STUDIOS
and it doesnt send anything. no errors tooXPOLKYT STUDIOS

1 Answers

0
votes

here's a good way to do it:

async def log(
    self,
    ctx,
    desc,
    title='**Title**',
    color=0xff0000,
    **kwargs
):

    guild = ctx.guild
    log_embed = discord.Embed(
        title=title,
        description=desc,
        color=color
    )
    for key, value in kwargs.items():
        if key == 'fields':
            for field in value:
                if len(field) == 2:
                    log_embed.add_field(
                        name=field[0],
                        value=field[1]
                    )
                else:
                    log_embed.add_field(
                        name=field[0],
                        value=field[1],
                        inline=field[2]
                    )
        if key == 'showauth':
            if value:
                author = ctx.author
                disp_name = author.display_name
                icon_url = author.avatar_url
                log_embed.set_author(
                    name=disp_name,
                    icon_url=icon_url
                )
                log_embed.set_thumbnail(
                    url=icon_url
                )
    now = datetime.now()
    log_embed.timestamp = now
    log_channel = discord.utils.get(guild.text_channels, name="channel_name")
    await log_channel.send(embed=log_embed)

also a quick example on using it:

        await self.log(
            ctx,
            'tdescription here',
            'title here',
            discord.Color.blue(),
            fields=[
                ('**Field**', "field value, you can add more fields")
            ],
            showauth=True
        )
        # you can use message, title, color, field(s), and the showauth