Discord.py倒计时,直到添加角色A.当成员在拥有角色B的情况下发送消息时,即使角色B已被删除,角色A也会被添加



当前当有人发送消息并拥有"饥饿;角色,机器人给他们一个倒计时角色(停止计数以重复(并计数60秒,然后给他们"倒计时";死的";角色然而,在定时器完成之后;死的";角色,即使";饥饿;已经被拿走了,我只想在用户仍然有";饥饿";。

@client.event
async def on_message(message):
Hunger = message.guild.get_role(957207332134223892)
Counting = message.guild.get_role(957525791426637834)
Dead = message.guild.get_role(852087847917715457)
if Hunger in message.author.roles:
if Counting not in message.author.roles:
if Dead not in message.author.roles:
await message.author.add_roles(Counting)
time.sleep(60)
if Hunger in message.author.roles:
await message.author.add_roles(Dead)
await message.author.remove_roles(Counting)

这似乎有效。改为使用asyncio.sleep()

import asyncio
@bot.command()
async def role(ctx):
Hunger = ctx.guild.get_role(957207332134223892)
Counting = ctx.guild.get_role(957525791426637834)
Dead = ctx.guild.get_role(852087847917715457)
if Hunger in ctx.author.roles:
if Counting not in ctx.author.roles:
if Dead not in ctx.author.roles:
await ctx.author.add_roles(Counting)
await asyncio.sleep(60)
await ctx.author.remove_roles(Counting)
if Hunger in ctx.author.roles:
await ctx.author.add_roles(Dead)

最新更新