本文介绍了websockets.exceptions.ConnectionClosed:WebSocket连接已关闭:代码= 4008(专用),原因=速率受限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Discord.py用于我的机器人,并且发生此错误: websockets.exceptions.ConnectionClosed:WebSocket连接已关闭:代码= 4008(专用),原因=速率受限.

I am using Discord.py for my bot and this error occurs:websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 4008 (private use), reason = Rate limited.

当我使用它时会发生这种情况:

It happens when I use this:

while true:
  activity=discord.Game(name=f"some stuff")
  await client.change_presence(activity=activity, status=status)

它具有异步功能,因此与异步/等待使用无关.

It is in an async function, so it is not related to async/await usage.

推荐答案

显然是因为您的状态更改频率很高,所以几乎没有延迟,这使Discord API将其视为API滥用.

Its apparently because of how frequently your status changes, there is almost no delay which makes the discord API considers it as an API abuse.

您可能想尝试为更改状态添加适当的延迟时间

You might wanna try adding a suitable delay for the changing status

while true:
  activity=discord.Game(name=f"some stuff")
  await client.change_presence(activity=activity, status=status)
  await asyncio.sleep(20) #time in seconds

这篇关于websockets.exceptions.ConnectionClosed:WebSocket连接已关闭:代码= 4008(专用),原因=速率受限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 07:01