python - Discord.Py:无法重命名频道并且没有任何异常
问题描述
我想每 5 秒重命名一次频道以创建动画。当我使用下面的代码时,它的工作速度很慢,并在一分钟或更长时间内重命名频道。
from asyncio import sleep
from discord.ext import commands
TOKEN = '(HIDEN)'
bot = commands.Bot(command_prefix='/')
async def voice_channel_animation():
await bot.wait_until_ready()
counter = 0
channel = bot.get_guild(821422769144594472).get_channel(822470935243128872)
animation = [" Create channel", " Create channel", " Create channel"]
size = len(animation)
while True:
await channel.edit(name=animation[counter])
counter = 0 if counter + 1 == size else counter + 1
await sleep(5)
bot.loop.create_task(voice_channel_animation())
bot.run(TOKEN)
我该如何解决这个问题?
解决方案
这是不可能的,编辑频道的速率限制是每个频道每 10 分钟 2 个请求,没有办法“绕过”这一点。您将改为每 5 分钟编辑一次频道。
while True:
await channel.edit(name=animation[counter])
counter = 0 if counter + 1 == size else counter + 1
await sleep(300)
推荐阅读
- javascript - 如何将对象数组过滤到js中的另一个对象数组?
- sql - 我怎样才能只为第一个条目显示“老板”?
- python - 使用 Matplotlib 将具有不同轴的两个图合二为一
- javascript - 多形零件类型在 Angular 中不起作用
- android - 如何通过 Flutter 保护存储在 iOS 和 Android 中的数据?
- java - java - 如何让一个类在java中进行数学运算?
- python - 熊猫:用逗号分割列后重复的列号
- python - 从地理数据框中检查多边形内的点
- java - Java Azure 函数不在本地执行
- javascript - 在 Firefox 上禁用时按钮不会失去焦点