Search code examples
pythondiscorddiscord.pyembed

Trying to create Embed Command discord.py


I am creating Embed cmd for my bot and I want my bot to ask for the channel in which the user wants to send the embed, but I ran into a error while doing so.

Code:

@bot.command()
async def buildembed(ctx):
    def check(message):
        return message.author == ctx.author and message.channel == ctx.channel

    await ctx.send('Waiting for a title')
    title = await bot.wait_for('message', check=check)
  
    await ctx.send('Waiting for a description')
    desc = await bot.wait_for('message', check=check)
    
    await ctx.send('Channel ID')
    guild = bot.get_guild(12345678)
    channel = guild.get_channel(await bot.wait_for('message', check=check))
    
    embed = discord.Embed(title=title.content, description=desc.content, color=discord.Color.blue())
    await channel.send(embed=embed)
raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an

exception: AttributeError: 'NoneType' object has no attribute 'send'

Your help would be really appreciated


Solution

  • channel = guild.get_channel(await bot.wait_for('message', check=check))
    await channel.send(embed=embed)
    

    channel is None, hence the error exception: AttributeError: 'NoneType' object has no attribute 'send'

    https://discordpy.readthedocs.io/en/stable/api.html?highlight=member_count#discord.Guild.get_channel

    get_channel() expects an int. You are passing a message object to it. You need to get the content of the message and then convert it to an int. Something like

    int((await bot.wait_for('message', check=check)).content)
    

    Really ugly code. You should refactor it to make it look more pretty. But that should work assuming the channel id that is provided is a valid channel id.