提问者:小点点

无法将嵌入发送到某些不和谐通道


我正在尝试向下面方法中的指定通道发送嵌入消息。 但是,当我将嵌入消息本身或与其他任何东西一起放入时,它不会发送。 但是,发送字符串可以很好地工作。

@bot.command()
@commands.cooldown(1, 10, commands.BucketType.user)
async def report(ctx, user, reason):
    if ctx.channel.id == 730496513255669881:
            channel = bot.get_channel(730432681657237594)
            embedstaff = discord.Embed(title="A new player report has been submitted!", color=0xff6a00)
            embedstaff.add_field(name="Player/User Reported", value=ctx.author.name, inline=True)
            embedstaff.add_field(name="Reporter", value="Lol", inline=True)
            embedstaff.add_field(name="Report Reason: " + reason, value="", inline=False)
            await channel.send("Heyy x3", embed = embedstaff)

是否有可供选择的方法将消息发送到指定的通道? 或者我现在用的方法有没有解决的办法? (怎么提到一个角色就太好了哈哈)


共1个答案

匿名用户

在获得role对象后,可以使用role.mentid来提及角色。 您可以使用getdiscord.utils获取角色

from discord.utils import get
#inside a command
role = get(ctx.guild.roles, name='role')
await ctx.send(f'Hello {role.mention}')

通过Id获取通道并向该通道发送嵌入式是标准方法。 该guild具有诸如system_channel,afk_channel,rules_channel的属性。 因此,如果设置了其中任何一个,您可以简单地从ctx获取它们

rules = ctx.guild.rules_channel

回答标题时,您可以检查发送嵌入的通道是否启用了嵌入。