For anyone coming across this in 2022:
how about put @client.event
instead of the @bot.command()
it fixed everything when I put @client.event... @bot.command() does not work you can type
To this ^, I don't recommend using @client.event
/ @bot.event
as you'd want to register your commands as a command.
If you want to simply make a command with an embed in your main.py
file, make sure you have something like:
import discord
from discord.ext import commands
intents = discord.Itents.default()
bot = commands.Bot(command_prefix='YOURPREFIX', description='description', intents=intents)
@bot.command(name="embed")
async def embed(ctx):
embed = discord.Embed(title='Title', description='Desc', color=discord.Color.random())
embed.add_field(name="Name", value="Value", inline=False)
await ctx.send(embed=embed)
However, I personally like separating my commands into a /commands
folder and with separate files for all of them as it's good practice for neater code.
For that, I use cogs.
/commands/embed.py
from discord.ext import commands
import discord
class EmbedCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name="embed")
async def embed(self, ctx):
embed = discord.Embed(title='Title', description='Desc', color=discord.Color.random())
embed.add_field(name="Name", value="Value", inline=False)
await ctx.send(embed=embed)
Then import it all into your main.py file:
from commands.embed import EmbedCog
bot.add_cog(EmbedCog(bot))