【问题标题】:discord bot edit role不和谐机器人编辑角色
【发布时间】:2020-12-15 14:03:03
【问题描述】:

我正在尝试做一个永久改变颜色的角色。我正在使用 discord.py 重写。

几个小时前它起作用了,现在我很困惑,因为它不再起作用了。我什么都没改变。

这是我的代码:

import discord
import asyncio
from discord.ext import commands

bot = commands.Bot(command_prefix='?', description="description")


@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')


@bot.command()
async def rgb(ctx, time: int):
    colours = [0xFF0000, 0x00FF00, 0x0000FF]
    i = 0
    selectedrole = ctx.guild.get_role(748128282859274251)

    while True:
        i = (i + 1) % 3
        print("This is printed")
        await selectedrole.edit(colour=discord.Colour(colours[i]))
        print("This will not be printed")
        await asyncio.sleep(time)


bot.run('xxxxx')

它不运行这行代码,只是停止(程序仍在运行,没有任何反应)

等待 selectedrole.edit(color=discord.Colour(colours[i]))

【问题讨论】:

  • 你有什么错误?
  • 没有错误
  • 永远不要在任何代码中提供您的机器人令牌。
  • 我将令牌更改为随机的东西。不是我的。 ;)

标签: python discord discord.py discord.py-rewrite


【解决方案1】:

这是因为您的机器人正在向 API 发送垃圾邮件,因此永远不会等待编辑代码。如果检测到超时错误,您可以尝试删除角色并重新创建角色,这可能会有所帮助,但无论哪种方式,您都应该避免向 API 发送垃圾邮件,因为它可能会删除您的机器人帐户。

【讨论】:

    【解决方案2】:

    是的,你必须建立一个计时器,我不会让这个通过命令改变。但请注意,Discord 不喜欢 Rainbow 角色,或者至少在 2018 年不喜欢它们。我没有任何其他信息。 [https://twitter.com/discord/status/1055182857709256704?s=20]

    顺便说一句。您可能必须更改您的 Bot-Token,因为您在这里泄露了它,但无论如何这里是代码。

    import asyncio
    from discord.ext import commands
    
    bot = commands.Bot(command_prefix='?', description="description")
    TOKEN = 'YOUR NEW TOKEN'
    
    
    @bot.event
    async def on_ready():
        print('Logged in as')
        print(bot.user.name)
        print(bot.user.id)
        print('------')
    
    
    @bot.command()
    async def rgb(ctx):
        colours = [0xFF0000, 0x00FF00, 0x0000FF]
        i = 0
        selectedrole = ctx.guild.get_role(101010101010101)
    
        while True:
            await asyncio.sleep(10)
            i = (i + 1) % 3
            print("Color changed")
            await selectedrole.edit(colour=discord.Colour(colours[i]))
    
    
    bot.run(TOKEN)
    

    【讨论】:

    • 我将令牌更改为随机的东西。不是我的。 ;)
    猜你喜欢
    • 2019-02-02
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 2021-01-06
    • 2021-01-22
    • 2018-12-29
    • 2021-01-15
    • 2021-05-22
    相关资源
    最近更新 更多