第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Discord.py 記錄刪除和編輯的消息

Discord.py 記錄刪除和編輯的消息

森林海 2023-04-18 17:36:14
我正在為我的服務(wù)器制作一個(gè)服務(wù)器機(jī)器人,我想記錄所有消息的刪除和編輯。它將登錄到一個(gè)日志通道供工作人員查看。在日志通道中,我想讓消息顯示被刪除的內(nèi)容或消息編輯之前的內(nèi)容以及消息編輯之后的內(nèi)容。我將如何讓機(jī)器人顯示已刪除或已編輯的消息?@client.event()async def on_message_delete(ctx):    embed=discord.Embed(title="{} deleted a message".format(member.name), description="", color="Blue")    embed.add_field(name="What the message was goes here" ,value="", inline=True)    channel=client.get_channel(channel_id)    await channel.send(channel, embed=embed)
查看完整描述

2 回答

?
炎炎設(shè)計(jì)

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊

您可以在使用時(shí)使用on_message_delete和on_message_edit,然后您應(yīng)該給函數(shù)消息而不是 ctx。

示例on_message_delete:

@client.event

async def on_message_delete(message):

? ? embed=discord.Embed(title="{} deleted a message".format(message.member.name),?

? ? description="", color="Blue")

? ? embed.add_field(name= message.content ,value="This is the message that he has?

? ? deleted",?

? ? inline=True)

? ? channel=client.get_channel(channel_id)

await channel.send(embed=embed)

示例on_message_edit:

@client.event

async def on_message_edit(message_before, message_after):

? ? embed=discord.Embed(title="{} edited a?

? ? message".format(message_before.member.name),?

? ? description="", color="Blue")

? ? embed.add_field(name= message_before.content ,value="This is the message before?

? ? any edit",?

? ? inline=True)

? ? embed.add_field(name= message_after.content ,value="This is the message after the?

? ? edit",?

? ? inline=True)

? ? channel=client.get_channel(channel_id)

await channel.send(embed=embed)


查看完整回答
反對(duì) 回復(fù) 2023-04-18
?
慕的地8271018

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊

該行:


embed=discord.Embed(title="{} edited a?

? ? message".format(message_before.member.name),?

? ? description="", color="Blue")

它不工作,因?yàn)閙essage沒有屬性member。它也不起作用,因?yàn)槟荒軐㈩伾O(shè)置為Blue或不進(jìn)行整數(shù)轉(zhuǎn)換的字符串。做到這一點(diǎn)的最好方法是定義一個(gè)像這樣的十六進(jìn)制輸入,color=0xFF0000這會(huì)使它變成紅色。


整行改變了:


embed = discord.Embed(title="{} deleted a message".format(message.author.name),

? ? ? ? ? ? ? ? ? ? ? description="", color=0xFF0000)

以下是經(jīng)過編輯的完整兩個(gè)命令。


@client.event

async def on_message_delete(message):

? ? embed = discord.Embed(title="{} deleted a message".format(message.author.name),

? ? ? ? ? ? ? ? ? ? ? ? ? description="", color=0xFF0000)

? ? embed.add_field(name=message.content, value="This is the message that he has deleted",

? ? ? ? ? ? ? ? ? ? inline=True)

? ? channel = client.get_channel(channelid)

? ? await channel.send(channel, embed=embed)



@client.event

async def on_message_edit(message_before, message_after):

? ? embed = discord.Embed(title="{} edited a message".format(message_before.author.name),

? ? ? ? ? ? ? ? ? ? ? ? ? description="", color=0xFF0000)

? ? embed.add_field(name=message_before.content, value="This is the message before any edit",

? ? ? ? ? ? ? ? ? ? inline=True)

? ? embed.add_field(name=message_after.content, value="This is the message after the edit",

? ? ? ? ? ? ? ? ? ? inline=True)

? ? channel = client.get_channel(channelid)

? ? await channel.send(channel, embed=embed)

我會(huì)在您的代碼頂部定義您想要使用的頻道。


logging_channel = channelID

# then at your two commands do this:

global logging_channel


查看完整回答
反對(duì) 回復(fù) 2023-04-18
  • 2 回答
  • 0 關(guān)注
  • 333 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)