为什么编辑消息时消息编辑嵌入不发送? (不和谐.py)

时间:2021-06-16 00:26:51

标签: python-3.x discord discord.py

编辑消息时,我的日志嵌入未发送。有人明白为什么吗?

@client.event
async def on_message_edit(before, after):
    with open('logchannel.json', 'r') as f:
        logs = json.load(f)

    logchannel = discord.utils.get(logs)
    embed = discord.Embed(color=0x0000ff, title="Message Edited", description=f"{before.author.mention} edited a message.")
    embed.add_field(name="Original Message", value=before.content, inline=True)
    embed.add_field(name="Edited Version", value=after.content, inline=True)   
    await logchannel.send(embed=embed)

1 个答案:

答案 0 :(得分:0)

discord.utils.get 用于从可迭代对象中获取具有指定属性的元素。您正在寻找discord.Client.get_channel

此外,r 模式和 inline=True 也是不必要的。它们是隐含的。

@client.event
async def on_message_edit(before, after):
    with open('logchannel.json') as f:
       logs = json.load(f)

    logchannel = client.get_channel(logs)
    embed = discord.Embed(color=0x0000ff, title='Message Edited', description=f'{before.author.mention} edited a message.')
    embed.add_field(name='Original Message', value=before.content)
    embed.add_field(name='Edited Version', value=after.content)
    await logchannel.send(embed=embed)