Reputation: 236
I'm trying to do a role that changes color permanently. I'm using discord.py rewrite.
A few hours ago it worked now I'm confused because it doesn't anymore. I changed nothing.
Here's my Code:
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')
It doesn't run this line of code and just stops (program still running, nothing happens)
await selectedrole.edit(colour=discord.Colour(colours[i]))
Upvotes: 0
Views: 3164
Reputation: 21
Yes, you have to build in a timer and I wouldn't let this change by command. But mind that Discord don‘t like Rainbow roles or at least didn't like them back in 2018. I do not got any other information. [https://twitter.com/discord/status/1055182857709256704?s=20]
btw. you probably have to change your Bot-Token, because you leaked it here but anyway here is the code.
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)
Upvotes: 1
Reputation: 1427
This is because your bot is spamming the API so the edit code never gets awaited. You can try delete the role if a timeout error is detected and create the role again which may help a little but either way you should avoid spamming the API as it could get your bot account removed.
Upvotes: 1