How to make a custom discord.py bot embed?

Viewed 43

I've been trying to make the bot send embeds but it's just not working, the code is executed with no errors but the embed doesn't get sent in the channel

@client.command()
async def embed(ctx):
    embed=discord.Embed(
        title='Title',
        description='Description',
        color=0x774dea
    )

    await ctx.send(embed=embed)

I already had the Privileged Gateway Intents enabled, but i added the intents to the code, same problem. Here is the full code:

import discord
from discord.ext import commands
from discord import Intents

_intents = Intents.default()
_intents.message_content = True


TOKEN = 'MYTOKENISHERE'

client = commands.Bot(command_prefix='$', intents=_intents)

@client.event
async def on_ready():
    print('We Have logged in as {0.user}'.format(client))

@client.command()
async def embed(ctx):
    embed=discord.Embed(
        title='Title',
        description='Description',
        color=0x774dea
    )

    await ctx.send(embed=embed)


client.run(TOKEN)
1 Answers

It seems like you may not have the correct Discord Intents enabled for your bot.

Here may be a fix for your issue:

  1. Go to the Discord Developer Portal and enable the options listed under Bot -> Privileged Gateway Intents

    Note: If your bot reaches over 100 servers, you'll be required to apply for each of these

    Image: here

  2. Replace your current commands.Bot instantiation with something like this (focus on the _intents and intents=_intents portions):

    from discord import Intents
    from discord.ext import commands
    
    _intents = Intents.default()
    
    # Enable or disable the intents that are required for your project
    _intents.message_content = True
    
    bot = commands.Bot(command_prefix='*', intents=_intents)
    
    # code here
    
    bot.run(your_token_here)
    

    If you're curious about customization of Intents and what you can do with them, read more here.

Related