Search code examples
pythonbotsembeddiscord.py

an issue with making a discord embed in python, no responses on command prompt nor discord


I'm trying to make some 'fun' commands as bots call them, and I wanted to embed them. However it doesnt spit out anything, not even an error on discord, nor on the command prompt, giving me no ideas on how to improve the code. I'd also like to implement a way to use the members: commands.Greedy[discord.Members] code so I can find who was the target for the command, but I think I need to solve this first. Any suggestions on how to do so? I also am stumped because I used the .format and the f string to try to use arguments, and I also tried using message, but that gave me a syntax error of 'Error 'list' object has no attribute 'mention''. I really cant understand the documents on the commands since they dont really give any examples of actual code, and I suck at understanding new stuff. Can someone figure this out?

from discord.ext import commands
import discord
bot= commands.Bot(command_prefix='0!')
@bot.event
async def on_message(message):
     if message.author == bot.user:
          return
     if message.content.startswith('Sample Text'):
          await message.channel.send('Sample Text')
@bot.command()
async def slap(ctx):
    embed = discord.Embed(color=0x00ff00, title='OH! Z E  S L A P !', description="ooh, that hurt.")
    embed.add_field(name="Man behind the slaughter:", value="test")
    await ctx.send(embed=embed)
bot.run('token here')```
-During this edit, when I just had the 'bot command' area, It seemed to have functioned still. This makes it even more confusing...

Solution

  • Overriding the default provided on_message() event forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message() event.

    @bot.event
    async def on_message(message):
         if message.author == bot.user:
              return
         if message.content.startswith('Sample Text'):
              await message.channel.send('Sample Text')
    
        await bot.process_commands(message)