discord.py 机器人找到要删除的频道消息,但显示其客户端 ID 与我的相同
discord.py bot finds channel messages to delete, but is showing its client id is the same as mine
我正在尝试创建一个名为“!clear”的命令,它只删除特定频道中的机器人消息。这看起来很简单,使用:
Client = discord.Client()
client = commands.Bot(command_prefix = "!")
@client.event
async def on_message(message):
if message.content.lower().startswith("!clear"):
async for x in client.logs_from(message.channel, limit = 100):
if str(message.author.id) == 'insert bots client id':
await client.delete_message(x)
client.run(token)
但是,我发现它没有删除任何消息。因此,在检查 message.author.id 之前,我添加了一个简单的 print(message.author.id) 来查看它正在获取哪些 ID。它似乎只吐出我的客户 ID 而没有看到自己的消息。奇怪的是,如果我将 author.id 检查更改为我的客户端 ID,那么它将删除我的消息以及机器人消息。所以出于某种原因,机器人认为它的客户端 ID 与我的相同,所以当它在不是我的测试服务器的服务器中时,它没有删除我的消息的正确权限,所以它失败了,即使我只希望它删除自己的消息。
任何帮助都会很棒。
你不是说
if x.author.id == "bot id here":
await client.delete_message(x)
毕竟,每条消息都放在 x
每次迭代中。使用 message
是指 async def on_message(message)
函数中的消息。这将是使用该命令的人。又名,你。
我正在尝试创建一个名为“!clear”的命令,它只删除特定频道中的机器人消息。这看起来很简单,使用:
Client = discord.Client()
client = commands.Bot(command_prefix = "!")
@client.event
async def on_message(message):
if message.content.lower().startswith("!clear"):
async for x in client.logs_from(message.channel, limit = 100):
if str(message.author.id) == 'insert bots client id':
await client.delete_message(x)
client.run(token)
但是,我发现它没有删除任何消息。因此,在检查 message.author.id 之前,我添加了一个简单的 print(message.author.id) 来查看它正在获取哪些 ID。它似乎只吐出我的客户 ID 而没有看到自己的消息。奇怪的是,如果我将 author.id 检查更改为我的客户端 ID,那么它将删除我的消息以及机器人消息。所以出于某种原因,机器人认为它的客户端 ID 与我的相同,所以当它在不是我的测试服务器的服务器中时,它没有删除我的消息的正确权限,所以它失败了,即使我只希望它删除自己的消息。
任何帮助都会很棒。
你不是说
if x.author.id == "bot id here":
await client.delete_message(x)
毕竟,每条消息都放在 x
每次迭代中。使用 message
是指 async def on_message(message)
函数中的消息。这将是使用该命令的人。又名,你。