如何解决不和谐机器人编辑角色
我正在尝试做一个永久改变颜色的角色。我正在使用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令牌,因为您在这里泄漏了它,但是无论如何,这里是代码。
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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。