【问题标题】:Task doesnt delete messages, discord.py任务不删除消息,discord.py
【发布时间】:2021-12-16 21:39:12
【问题描述】:

所以基本上这是我为我的服务器制作的战利品箱,它应该自行删除.. 但是当我醒来时,我检查我的频道看到 4-5 条消息,而不是 1 条!有什么帮助吗? - 编辑 - 我应该提到当我让 x = 说 30 分钟并删除时间 29 分钟时,这工作正常。

x = 180
@tasks.loop(minutes=x)
async def send():
    open('acceptloot.txt', 'w').close()
    response = "Frag has sent supplies into the field, if you're lucky you can get some!"
    channel = bot.get_channel(903563274807808040)
    await channel.send(file=discord.File('lootbox.png'), delete_after=10650)
    message = await channel.send(response, delete_after=10750)
    await message.add_reaction('✅')

@send.before_loop
async def before():
    await bot.wait_until_ready()

send.start()

【问题讨论】:

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


    【解决方案1】:

    你可以用旧方法试试,不用 "delete_after=":

    message = 'your message' # your message
    msg = await bot.send(message) # sends message
    await asyncio.sleep(5) # wait 5 seconds  
    await msg.delete() # delete the message
    

    【讨论】:

    • 我试试,谢谢
    • 是的,这也不起作用..事实上,与我之前的方式相比,出现并保留了更多消息.. :( 会不会是“等待 x 秒”太长了?
    猜你喜欢
    • 2018-06-29
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 2019-02-20
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多