编辑消息时,我的日志嵌入未发送。有人明白为什么吗?
@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)
答案 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)