Mahir Çınar Girgin
Hectopat
Daha fazla
- Cinsiyet
- Erkek
- Meslek
- Öğrenci
Yeni bir Discord botu yapmaya çalışıyorum fakat Slash command cooldown'larında sorun yaşıyorum. Importlarım şu şeklide;
Cooldown errorunu şu şeklide alıyorum (error handler) ve düzgünce çalışıyor;
Bot için cooldown ile donatılmış basit bir kod;
Bunu iki kere arda arda 30 saniye içerisinde yazdığım zaman cooldown mesajını alabiliyorum.
Bunun gibi bir tane daha komutum var. Adı claim. Onun için de cooldown'ı alabiliyorum fakat benim burada asıl yapmak istediğim şey Bütün cooldownları tek bir komutta toplayıp göstermek. Bunun için cooldown adlı bir komut daha açtım;
Bunu çalıştırdığımda şu şekilde bir hata alıyorum;
Bu biraz saçma çünkü 56. satır cdown = error.retry_after . Bu satır diğer komutların (örneğin claim ve beg) hata alma kısmında düzgünce çalışıyor.
Bir yerlerde hata yaptığımı biliyorum fakat tam olarak nerede olduğunu saptayamadım. Yardım edebilirseniz çok müteşekkir olacağım. Şimdiden teşekkürler.
Python:
import asyncio
from utils import TOKEN
import aiosqlite
import nextcord
from nextcord import Interaction, SlashOption, ChannelType
from nextcord.abc import GuildChannel
from nextcord.ext import commands, tasks
import random
import time
import cooldowns
from cooldowns import SlashBucket, CallableOnCooldown
Cooldown errorunu şu şeklide alıyorum (error handler) ve düzgünce çalışıyor;
Python:
@Bot.event
async def on_application_command_error(interaction: Interaction, error):
error = getattr(error, "original", error)
cdown = error.retry_after
embed = nextcord.Embed(title="Hold on", colour=nextcord.Colour.from_rgb(255, 0, 0))
# cdown = "%.0f" % error.retry_after
if isinstance(error, CallableOnCooldown):
cdown = "%.0f" % error.retry_after
if int(cdown) >= 3600:
cd = round(error.retry_after)
hours = str(cd // 3600)
minute = int(cd // 60)
minutes = str(minute % 60)
seconds = str(cd % 60)
embed.add_field(name="You are on cooldown for this command", value=f"Remaining time: `{hours} hours {minutes} minutes {seconds} seconds`")
await interaction.response.send_message(embed=embed)
elif int(cdown) >= 60 and int(cdown) < 3600:
cd = round(error.retry_after)
minutes = str(cd // 60)
seconds = str(cd % 60)
embed.add_field(name="You are on cooldown for this command", value=f"Remaining time: `{minutes} minutes {seconds} seconds`")
await interaction.response.send_message(embed=embed)
elif int(cdown) < 60:
embed.add_field(name="You are on cooldown for this command", value=f"Remaining time: `{cdown} seconds`")
await interaction.response.send_message(embed=embed)
Bot için cooldown ile donatılmış basit bir kod;
Python:
@Bot.slash_command(guild_ids=[test_guild], name="beg", description="Beggin in the street. Poor guy.")
@cooldowns.cooldown(1, 30, bucket=cooldowns.SlashBucket.author)
async def beg(interaction: Interaction):
chances = random.randint(1, 4)
if chances == 1:
embed = nextcord.Embed(title="You begged", colour=nextcord.Colour.from_rgb(255, 0, 0))
embed.add_field(name="And you got nothing.", value="Poor guy")
return await interaction.response.send_message(embed=embed)
amount = random.randint(10, 100)
res = await update_wallet(interaction.user, amount)
if res == 0:
return await interaction.response.send_message("No account found so one has been created for you. Please run the command again!")
embed = nextcord.Embed(title="You begged", colour=nextcord.Colour.from_rgb(35, 209, 0))
embed.add_field(name="Wow someone gave you some coins", value=f"You got `{amount} coins`")
await interaction.response.send_message(embed=embed)
Bunu iki kere arda arda 30 saniye içerisinde yazdığım zaman cooldown mesajını alabiliyorum.
Bunun gibi bir tane daha komutum var. Adı claim. Onun için de cooldown'ı alabiliyorum fakat benim burada asıl yapmak istediğim şey Bütün cooldownları tek bir komutta toplayıp göstermek. Bunun için cooldown adlı bir komut daha açtım;
Python:
@Bot.slash_command(guild_ids=[test_guild])
async def cooldown(interaction: Interaction):
claim_c = Bot.get_command("claim")
cooldown_claim = claim_c.get_cooldown_retry_after(interaction)
beg_c = Bot.get_command("beg")
cooldown_beg = beg_c.get_cooldown_retry_after(interaction)
# await interaction.response.send_message(f"Cooldown left {command.get_cooldown_retry_after(ctx)}")
embed = nextcord.Embed(title="COOLDOWNS", colour=nextcord.Colour.from_rgb(255, 0, 0))
if cooldown_claim >= 3600:
cd = round(cooldown_claim)
hours = str(cd // 3600)
minute = int(cd // 60)
minutes = str(minute % 60)
seconds = str(cd % 60)
embed.add_field(name="Claim", value=f"`{hours} hours {minutes} minutes {seconds} seconds`", inline=False)
elif int(cooldown_claim) >= 60 and int(cooldown_claim) < 3600:
cd = round(cooldown_claim)
minutes = str(cd // 60)
seconds = str(cd % 60)
embed.add_field(name="Claim", value=f"`{minutes} minutes {seconds} seconds`", inline=False)
elif int(cooldown_claim) < 60 and int(cooldown_claim) > 0:
embed.add_field(name="Claim", value=f"`{cooldown_claim} seconds`", inline=False)
elif int(cooldown_claim) == 0:
embed.add_field(name="Claim", value="`Ready`", inline=False)
if cooldown_beg >= 3600:
cd = round(cooldown_beg)
hours = str(cd // 3600)
minute = int(cd // 60)
minutes = str(minute % 60)
seconds = str(cd % 60)
embed.add_field(name="Beg", value=f"`{hours} hours {minutes} minutes {seconds} seconds`", inline=False)
elif int(cooldown_beg) >= 60 and int(cooldown_beg) < 3600:
cd = round(cooldown_beg)
minutes = str(cd // 60)
seconds = str(cd % 60)
embed.add_field(name="Beg", value=f"`{minutes} minutes {seconds} seconds`", inline=False)
elif int(cooldown_beg) < 60 and int(cooldown_beg) > 0:
cd = round(cooldown_beg)
embed.add_field(name="Beg", value=f"`{cd} seconds`", inline=False)
elif int(cooldown_beg) == 0.0:
embed.add_field(name="Beg", value="`Ready`", inline=False)
await interaction.response.send_message(embed=embed)
Bunu çalıştırdığımda şu şekilde bir hata alıyorum;
Kod:
Ignoring exception in on_application_command_error
Traceback (most recent call last):
File "C:\Users\nmgir\PycharmProjects\girginbot.py\lib\site-packages\nextcord\client.py", line 499, in _run_event
await coro(*args, **kwargs)
File "C:\Users\nmgir\OneDrive\Desktop\slashcomamnds\main.py", line 56, in on_application_command_error
cdown = error.retry_after
AttributeError: 'AttributeError' object has no attribute 'retry_after'
Bu biraz saçma çünkü 56. satır cdown = error.retry_after . Bu satır diğer komutların (örneğin claim ve beg) hata alma kısmında düzgünce çalışıyor.
Bir yerlerde hata yaptığımı biliyorum fakat tam olarak nerede olduğunu saptayamadım. Yardım edebilirseniz çok müteşekkir olacağım. Şimdiden teşekkürler.
Son düzenleyen: Moderatör: