tasks.loop 15 分钟后无效的 Webhook 令牌

时间:2021-03-23 04:18:58

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

我正在尝试制作一个不和谐机器人,它每小时在特定频道中发送一条消息。我决定用一个命令开始循环。

from discord.ext import commands, tasks
from discord_slash import SlashCommand, SlashContext
   
bot = commands.Bot(command_prefix="/",help_command=None)
slash = SlashCommand(bot,sync_commands=True)

@tasks.loop(minutes=1,count=20)
    async def loop(ctx: SlashContext):
        await ctx.send("loop")
    
@slash.slash(name="start_loop")
async def _start_loop(ctx: SlashContext):
    await ctx.respond(eat=True)
    loop.start(ctx)
    
bot.run("TOKEN")

该命令在不循环时完美运行,但无论我在循环 15 分钟后设置什么间隔,它都会引发此错误

discord.errors.HTTPException: 401 Unauthorized (error code: 50027): Invalid Webhook Token

这是什么原因造成的?

解决方案:

ctx.send() 替换为 ctx.channel.send(),因为前者在 15 分钟后停止工作

0 个答案:

没有答案