Answer the question
In order to leave comments, you need to log in
How to change the code to remove errors after 2-3 clicks on the button?
I use buttons to issue roles, but for some reason I press 1-2 times and a 100% error crashes.
Here is the code:
@bot.command()
async def test(ctx):
emb = discord.Embed(title = 'Выдача ролей Discord', description = "Вы можете самостоятельно добавить/убрать себе нужную роль нажав на нужную кнопку под данным сообщением!", colour = 0xFF005C)
emb.set_image(url = 'https://media.discordapp.net/attachments/716567643523645470/856089732953800734/-4.png?width=701&height=701')
emb.set_footer(text = 'Weazel News', icon_url = 'https://media.discordapp.net/attachments/716571065270140938/880854176735854622/-6.png?width=701&height=701')
await ctx.send(
embed = emb,
components = [
Button(style = ButtonStyle.green, label = "Получить роль Гражданина"),
Button(style = ButtonStyle.blue, label = "Получить роль Специального Гостя"),
Button(style = ButtonStyle.red, label = "Очистить роли")
]
)
while True:
res2 = await bot.wait_for('button_click')
channel = res2.guild.get_channel(882269213807497327)
current_time = datetime.now().time()
roleq = res2.guild.get_role(882256355887554581)
log = discord.Embed(title = 'Добавление ролей', colour = 0x00FF00)
log.set_thumbnail(url = f'{res2.author.avatar_url}')
log.add_field(name="Участник", value= '<@%d>' % (res2.author.id), inline=True)
log.add_field(name="Роль", value= '<@&882256355887554581>', inline=True)
log.set_footer(icon_url = 'https://media.discordapp.net/attachments/716571065270140938/880854176735854622/-6.png?width=701&height=701', text = "Сегодня в %d:%d" % (current_time.hour, current_time.minute))
if res2.component.label.startswith("Получить роль Гражданина"):
await res2.respond(content="Выдана роль: <@&882256355887554581>")
await channel.send(embed = log)
log2 = discord.Embed(title = 'Запрос на выдачу ролей', timestamp= datetime.utcnow(), colour = 0x0000FF)
log2.set_thumbnail(url = f'{res2.author.avatar_url}')
log2.add_field(name="Участник", value= '<@%d>' % (res2.author.id), inline=True)
log2.add_field(name="Роль", value= '<@&882265303684354058>', inline=True)
log2.set_footer(icon_url = 'https://media.discordapp.net/attachments/716571065270140938/880854176735854622/-6.png?width=701&height=701')
if res2.component.label.startswith("Получить роль Специального Гостя"):
await res2.respond(content="Запрос получен, ждите одобрение от Weazel News!")
await channel.send(
embed = log2,
components = [
[Button(style = ButtonStyle.green, label = "Принять"), Button(style = ButtonStyle.red, label = "Отказать в выдаче роли")]
])
qqq = await bot.wait_for('button_click')
roles = res2.guild.get_role(882265303684354058)
log3 = discord.Embed(title = 'Запрос на выдачу ролей', timestamp= datetime.utcnow(), colour = 0x0000FF)
log3.set_thumbnail(url = f'{res2.author.avatar_url}')
log3.add_field(name="Участник", value= '<@%d>' % (res2.author.id), inline=True)
log3.add_field(name="Роль", value= '<@&882265303684354058>', inline=True)
log3.add_field(name="Одобрил сотрудник", value= '<@%d>' % (qqq.author.id), inline=False)
log3.set_footer(icon_url = 'https://media.discordapp.net/attachments/716571065270140938/880854176735854622/-6.png?width=701&height=701')
if qqq.component.label.startswith("Одобрить"):
await channel.send(
embed = log3)
await qqq.message.delete()
await qqq.author.add_roles(roles)
www = await bot.wait_for('button_click')
log4 = discord.Embed(title = 'Запрос на выдачу ролей', timestamp= datetime.utcnow(), colour = 0x0000FF)
log4.set_thumbnail(url = f'{res2.author.avatar_url}')
log4.add_field(name="Участник", value= '<@%d>' % (res2.author.id), inline=True)
log4.add_field(name="Роль", value= '<@&882265303684354058>', inline=True)
log4.add_field(name="Отклонил сотрудник", value= '<@%d>' % (www.author.id), inline=False)
log4.set_footer(icon_url = 'https://media.discordapp.net/attachments/716571065270140938/880854176735854622/-6.png?width=701&height=701')
if www.component.label.startswith("Отказать"):
await channel.send(
embed = log4)
await www.message.delete()
log5 = discord.Embed(title = 'Удаление ролей', timestamp= datetime.utcnow(), colour = 0x00FF00)
log5.set_thumbnail(url = f'{res2.author.avatar_url}')
log5.add_field(name="Участник", value= '<@%d>' % (res2.author.id), inline=True)
log5.add_field(name="Роль", value= '<@&882256355887554581>', inline=True)
log5.set_footer(icon_url = 'https://media.discordapp.net/attachments/716571065270140938/880854176735854622/-6.png?width=701&height=701')
if res2.component.label.startswith("Очистить роли"):
await res2.respond(content="Роли удалены")
await channel.send(embed = log5)
await res2.author.remove_roles(roles, roleq)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question