正在尝试创建嵌入命令 discord.py

Trying to create Embed Command discord.py

我正在为我的 bot 创建 Embed cmd,我希望我的 bot 询问用户想要发送嵌入的频道,但我 运行 在这样做时遇到了错误。

代码:

@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'

非常感谢您的帮助

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

channelNone,因此错误 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() 需要一个整数。您正在将 message 对象传递给它。您需要获取消息的内容,然后将其转换为 int。像

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

代码真难看。你应该重构它,使它看起来更漂亮。但假设提供的频道 ID 是有效的频道 ID,那应该可以工作。

您传递的不是 id(消息内容),而是 guild.get_channel()

中的消息对象
   channel_id = await bot.wait_for('message', check=check)
   channel = guild.get_channel(int(channel_id.content))