语音频道中的倒计时计时器(Discord.py)

2024-04-19 09:29:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一个python机器人,它在倒计时中每小时编辑一个语音频道名称,并在它达到0时重置。它用于在设定的时间重置服务器。我有语音频道的编辑,但我一直在想如何让计数器在每次更新时下降一个。目前,机器人每小时更新一次vc名称,但计数器从不下降。它总是停留在24或23

有人能帮我吗

以下是我目前掌握的代码:

from discord.ext import commands, tasks

token = 'token'
bot = commands.Bot(command_prefix='!')

@bot.event
async def on_ready():
    change_status.start()
    print('bot is active')

@tasks.loop(seconds=3600)
async def change_status():
    channel = bot.get_channel(id)
    counter = 24
    counterint = counter - 1
    if counterint == 0:
        await channel.edit(name=f"NA reset: {counter}h")
    else:
        await channel.edit(name=f"NA reset: {counterint}h")
    print('timer down 1')

bot.run(token)

Tags: 名称token编辑botcounterchannel计数器机器人