【发布时间】:2020-12-08 18:37:32
【问题描述】:
我正在尝试执行一个命令,当在用户指定的时间内没有发送任何消息时,机器人会发送一个随机主题,但是,我似乎无法正确设置计时部分。
我的问题是:如何检查频道中 X 分钟内是否没有消息发送? 这是我想出的代码:
@bot.command()
async def timedtopic(ctx, time : int):
global keepLooping
timer = dt.datetime.utcnow() + dt.timedelta(seconds=time)
keepLooping = True
embed = discord.Embed(title="Reviver's topic is", description=(random.choice(List)))
await asyncio.sleep(time)
while keepLooping:
if timer > ctx.channel.last_message.created_at and ctx.channel.last_message.author != bot.user:
await ctx.send(embed=embed)
【问题讨论】:
标签: python discord discord.py discord.py-rewrite