You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Repl.it上Discord.py机器人首次运行触发429限流问题求助

Repl.it上Discord.py机器人首次运行触发Cloudflare限流(错误1015)的解决方法

错误原因解析

你遇到的是Cloudflare的1015错误(IP临时封禁),并非Discord官方的API限流。Repl.it的服务器IP段因大量用户同时运行Discord机器人,请求频率过高,被Discord的Cloudflare防护系统判定为异常流量,临时禁止该IP访问Discord服务。

代码冗余修正

你的代码重复初始化了client对象,会增加不必要的请求,先删除冗余行:

# 删除这行重复的初始化代码
client = discord.Client()

具体解决步骤

  • 等待重试:Cloudflare的临时封禁通常持续几分钟到几小时,过段时间再运行机器人即可。
  • 更换Repl运行IP:新建Repl项目或重启当前Repl,Repl可能会分配新的IP地址,避开封禁。
  • 关闭slash命令自动同步:将slash = SlashCommand(client, sync_commands=True)改为sync_commands=False,自动同步会发送额外请求加重IP段负载,等IP恢复正常后再开启同步。

修正后的代码示例

from keep_alive import keep_alive
import discord
from discord.ext import commands, tasks
from discord_slash import SlashCommand
from discord_slash import SlashContext
import os

# 仅初始化一次Bot实例
client = commands.Bot(command_prefix="!")
# 临时关闭自动同步,减少请求量
slash = SlashCommand(client, sync_commands=False)

@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.online, activity=discord.Game(name='Bolton FC'))
    print("Bot online")

@slash.slash(name="ping", description="Ping Pong")
async def _ping(ctx: SlashContext):
    await ctx.send(content="pong!")

keep_alive()
client.run(os.getenv("TOKEN"))

内容的提问来源于stack exchange,提问作者Aarik Ghosh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 09:05:22