我有这段代码应该每分钟发送一次Loop Check
,但是除了Flask,d.py和GET请求之外没有其他输出
代码:
class infinityplus(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@tasks.loop(minutes=1)
async def check_date():
with open('giveaway.json', 'r') as rf:
giveaway = json.load(rf)
ctx = giveaway['ctx']
message = giveaway['message']
prize = giveaway['prize']
today = date.today()
date1 = today.strftime("%d/%m/%Y")
print('Loop Check')
if date1 == '22/10/2021':
users = await message.reaction.users().flatten()
winner = random.choice(users)
embed2 = discord.Embed(
title='Giveaway Ended',
description=
f'__**Winner**__: {winner.mention}\n__**Hosted by**__: {ctx.author.mention}',
colour=red)
await message.edit(embed=embed2)
await message.channel.send(
f'Congrats {winner.mention}, you won {prize}\n\nhttps://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id}\n({ctx.author.id})'
)
def setup(bot):
bot.add_cog(infinityplus(bot))
答案 0 :(得分:0)
您需要创建一个错误处理程序。否则,如果任务中发生错误,它将以静默方式通过。
import logging, traceback
async def on_error(event, *args, **kwargs):
print('Something went wrong!')
logging.warning(traceback.format_exc())