簡體   English   中英

不和諧機器人編輯角色

[英]discord bot edit role

我正在嘗試扮演一個永久改變顏色的角色。 我正在使用 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(colour=discord.Colour(colours[i]))

這是因為您的機器人正在向 API 發送垃圾郵件,因此永遠不會等待編輯代碼。 如果檢測到超時錯誤,您可以嘗試刪除角色並再次創建角色,這可能會有所幫助,但無論哪種方式,您都應該避免向 API 發送垃圾郵件,因為它可能會刪除您的機器人帳戶。

是的,你必須內置一個計時器,我不會讓這個通過命令改變。 但請注意,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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM