在 discord.py 中删除机器人的消息 [英] Deleting a bot's message in discord.py
问题描述
我已经进行了所有正确的导入,并尝试从其他帖子中寻找答案,但它似乎不太适合我的问题.我正在尝试随机发送一条消息,我可以做到.但是,经过一定的冷却时间后,我似乎无法删除这些消息.然而,冷却时间不是问题.它正在删除机器人消息.我知道如何删除用户的消息,但我对如何删除机器人消息一无所知.你能帮忙的话,我会很高兴.这是我的代码,但我的令牌 ID 和导入除外.
I have already made all of the proper imports and I have tried looking for answers from other posts but it seems to not quite fit my issue. I am trying to randomly send a message, which I can do. However I can not seem to delete the messages after a certain cool down time. The cool down time is not the issue however. It is deleting the bots message. I know how to delete a user's message but I have very little idea on how I would delete the bots message. Any help would be nice. Here is my code with the exception of my token ID and imports.
async def background_loop():
await client.wait_until_ready()
while not client.is_closed:
channel = client.get_channel('397920718031159318')
messages = ["A random cat has appeared", "oh look its a cate"]
await client.send_message(channel, random.choice(messages))
time.sleep(3) #I am using this as the cool down time to delete the
#message
await client.delete_message(messages)
await asyncio.sleep(4)
推荐答案
while not client.is_closed:
channel = client.get_channel('397920718031159318')
messages = ["A random cat has appeared", "oh look its a cate"]
message = await client.send_message(channel, random.choice(messages))
await asyncio.sleep(3)
await client.delete_message(message)
await asyncio.sleep(4)
您必须捕获 send_message
产生的消息对象,然后将该对象发送到 delete_message
You have to capture the message object that send_message
produces, and then send that object to delete_message
这篇关于在 discord.py 中删除机器人的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!