python-3.x - 在 discord.py 中删除机器人的消息

标签 python-3.x discord discord.py

我已经进行了所有正确的导入,并且我尝试从其他帖子中寻找答案,但它似乎不太适合我的问题。我正在尝试随机发送一条消息,我可以做到。但是,经过一段时间的冷却后,我似乎无法删除这些消息。然而,冷却时间不是问题。它正在删除机器人消息。我知道如何删除用户的消息,但我对如何删除机器人消息知之甚少。你能帮忙的话,我会很高兴。这是我的代码,但我的 token ID 和导入除外。

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

关于python-3.x - 在 discord.py 中删除机器人的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49159850/

相关文章:

Python 公共(public)假期在工作日

oauth-2.0 - Discord OAuth2 如何检查机器人是否在(加入)公会

python - 更新机器人而不关闭它discord python

python - 如何遍历一个类的所有实例?

python - 如何最有效地存储矩阵的值

javascript - 是否可以计算用户加入之间的秒数?

python - 超时不适用于 Wait_For_Message Discord PY

python-3.x - Python为消息添加自定义 react

python - 我的 for 循环没有根据条件删除数组中的项目? Python

javascript - Ping 问题discord.js