首页 > 解决方案 > 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)

我该如何解决这个问题?

标签: pythondiscorddiscord.py

解决方案


这是不可能的,编辑频道的速率限制是每个频道每 10 分钟 2 个请求,没有办法“绕过”这一点。您将改为每 5 分钟编辑一次频道。

while True:
    await channel.edit(name=animation[counter])
    counter = 0 if counter + 1 == size else counter + 1
    await sleep(300)

推荐阅读