删除机器人发送的某些消息

时间:2018-09-26 01:05:38

标签: python python-3.x discord discord.py

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

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)

2 个答案:

答案 0 :(得分:1)

您正试图删除一个字符串,该字符串也用于创建消息。它与发送的实际discord.Message对象无关。您需要捕获该对象,它是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)

答案 1 :(得分:0)

您的漫游器是否有权删除您正在使用的服务器上的消息?

您可以通过添加管理邮件权限在服务器设置中启用它。