机器人问题

时间:2020-10-18 16:37:04

标签: python python-3.x discord.py

我的代码有问题。

当我启动漫游器并键入$ start时,它可以运行,但几秒钟后停止。

我是一个初学者,所以我不知道为什么会这样。

这是我的代码:

import discord
import asyncio
import colorsys
from discord import utils
from discord.ext import commands
from config import settings
from discord.utils import get
bot = commands.Bot(command_prefix = settings['prefix'])
@bot.command()
async def start(ctx):
    role_id = settings['roleid']
    role = ctx.guild.get_role(int(role_id))
    color_rgb = 0
    while True:
        while True:
            color_rgb = color_rgb + 5
            await role.edit(colour = discord.Colour.from_rgb(255, color_rgb, 0))
            if (color_rgb == 255):
                print('done')
                break
        while True:
            color_rgb = color_rgb - 5
            await role.edit(colour = discord.Colour.from_rgb(color_rgb, 255, 0))
            if (color_rgb == 0):
                print ('done')
                break
        while True:
            color_rgb = color_rgb + 5
            await role.edit(colour = discord.Colour.from_rgb(0, 255, color_rgb))
            if (color_rgb == 255):
                print ('done')
                break
        while True:
            color_rgb = color_rgb - 5
            await role.edit(colour = discord.Colour.from_rgb(0, color_rgb, 255))
            if (color_rgb == 0):
                print ('done')
                break
        while True:
            color_rgb = color_rgb + 5
            await role.edit(colour = discord.Colour.from_rgb(color_rgb, 0, 255))
            if (color_rgb == 255):
                print ('done')
                break
        while True:
            color_rgb = color_rgb - 5
            await role.edit(colour = discord.Colour.from_rgb(255, 0, color_rgb))
            if (color_rgb == 0):
                print ('done')
                break
bot.run(settings['token'])

2 个答案:

答案 0 :(得分:0)

要摆脱所有麻烦,您可以在color_rgb = 0语句之后尝试以下操作:

while True:
    for c in range(0,256,5):
        await role.edit(colour = discord.Colour.from_rgb(255, c, 0))
        print("done")

    for c in range(0,256,5):
        await role.edit(colour = discord.Colour.from_rgb(255-c, 255, 0))
        print("done")

    for c in range(0,256,5):
        await role.edit(colour = discord.Colour.from_rgb(0, 255, c))
        print("done")

    for c in range(0,256,5):
        await role.edit(colour = discord.Colour.from_rgb(0, 255-c, 255)
        print("done")

    for c in range(0,256,5):
        await role.edit(colour = discord.Colour.from_rgb(c, 0, 255))
        print("done")

    for c in range(0,256,5):
        await role.edit(colour = discord.Colour.from_rgb(255, 0, 255-c))
        print("done")
    print("all done")

答案 1 :(得分:0)

嘿,我读了一些有关它的东西。 Discord不想使用“彩虹角色”,并且每天将角色编辑限制为1000个。

在这里阅读:https://support.discord.com/hc/en-us/community/posts/360067748172-Increase-Role-Edit-rate-limit-to-86400#:~:text=The%20rate%20limit%20for%20editing,1000%20requests%20per%2024%20hours

在这里:https://twitter.com/discord/status/1055182857709256704?lang=en

您可以做的就是每天最多更改1000次颜色,也许只有在登录后才能更改