我正在尝试制作一个不和谐机器人,它每小时在特定频道中发送一条消息。我决定用一个命令开始循环。
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 分钟后停止工作