简体   繁体   中英

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

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.

You are not passing the id (Message Content) but the message object in guild.get_channel()

   channel_id = await bot.wait_for('message', check=check)
   channel = guild.get_channel(int(channel_id.content))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM