删除机器人发送的某些消息 [英] Delete certain message bot sends

查看:93
本文介绍了删除机器人发送的某些消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个拼盘游戏,如果要解决还是不能解决,我想删除原始消息。尝试使用client.delete_message(nameofmsghere),但不会删除它。

Have a scramble game that I want to delete the original message if it was solved or not solved. Tried client.delete_message(nameofmsghere) but it's not deleting it.

if message.content.startswith('!scramble'):
    async with aiohttp.post("http://watchout4snakes.com/wo4snakes/Random/RandomWord") as post:
        assert isinstance(post, aiohttp.ClientResponse)
        word = await post.read()
    word = word.decode()
    print(word)
    scrambled = random.sample(word, len(word))
    scrambled = ''.join(scrambled)
    scramblemsg = "The word scramble is: `{}`! You have 10 seconds to solve...".format(scrambled)
    await client.send_message(message.channel, scramblemsg)
def check(m):
    return m.content == word
scrambleloot = random.randint(5,15)
msg = await client.wait_for_message(timeout= 10, check=check)
try:
    if msg:
        await client.send_message(message.channel, "Nice job! {} solved the scramble for ${}! The word was {}!".format(msg.author.mention, scrambleloot, word))
        await client.delete_message(scramblemsg)
        add_dollars(msg.author, scrambleloot)
    else:
        if msg is None:
            await client.send_message(message.channel, "Oops! Nobody solved it. The word was {}!".format(word))
            await client.delete_message(scramblemsg)


推荐答案

您正试图删除一个字符串,该字符串也用于创建消息。它与实际的 discord.Message 已发送的对象,您需要捕获该对象,即 send_message

You're attempting to delete a string, which you also used to create the message. It has no relation to the actual discord.Message object that was sent. You need to capture that object, which is the return value of send_message

text = "The word scramble is: `{}`! You have 10 seconds to solve...".format(scrambled)
scramblemsg  = await client.send_message(message.channel, text)
...
await client.delete_message(scramblemsg)

这篇关于删除机器人发送的某些消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆