Cooldown for guessing_game

This commit is contained in:
CreeperXP 2021-10-19 15:28:42 +00:00
parent 48712e3ce3
commit 5722137291
3 changed files with 156 additions and 144 deletions

Binary file not shown.

View File

@ -8,7 +8,13 @@ class guessing_game(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f'Для использования команды повторно жди {round(error.retry_after, 2)} секунд')
@commands.command(aliases = ['guess', 'номера', 'угадайка'])
@commands.cooldown(1, 15, commands.BucketType.user)
async def guessing_game(self, ctx):
await ctx.send('Введи число от 1 до 10')

60
main.py
View File

@ -8,7 +8,6 @@ import requests
import random
import asyncio
PREFIX = "$"
bot = commands.Bot(command_prefix=PREFIX, description="Hi")
bot.remove_command("help")
@ -21,9 +20,7 @@ ctime = time.strftime("Today is %X %x", time.localtime())
async def on_ready():
print(f"Bot logged as {bot.user} | {version}")
print(f"{ctime}")
await bot.change_presence(
status=nextcord.Status.online, activity=nextcord.Game("$help")
)
await bot.change_presence(status=nextcord.Status.online,activity=nextcord.Game("$help"))
@bot.command()
@ -31,11 +28,12 @@ async def help(ctx):
await ctx.send(
f"Мои команды: {PREFIX}help | {PREFIX}ping | {PREFIX}clear | {PREFIX}hello | {PREFIX}github | {PREFIX}ver | {PREFIX}say | {PREFIX}serverinfo | {PREFIX}clean | {PREFIX}send_m"
)
print(f"[Logs:utils] Информация о командах бота была выведена | {PREFIX}help")
print(
f"[Logs:utils] Информация о командах бота была выведена | {PREFIX}help"
)
@bot.command(
aliases=[
@bot.command(aliases=[
"Ping",
"PING",
"pING",
@ -48,8 +46,7 @@ async def help(ctx):
"ПОНГ",
"пОНГ",
"понг",
]
)
])
async def __ping(
ctx,
): # Объявление асинхронной функции __ping с возможностью публикации сообщения
@ -131,17 +128,23 @@ async def serverinfo(ctx):
serverinfoEmbed = nextcord.Embed(color=ctx.author.color)
serverinfoEmbed.add_field(name="Название", value=f"{ctx.guild.name}", inline=False)
serverinfoEmbed.add_field(
name="Кол-во юзеров", value=f"{ctx.guild.member_count}", inline=False
)
serverinfoEmbed.add_field(name="Название",
value=f"{ctx.guild.name}",
inline=False)
serverinfoEmbed.add_field(name="Кол-во юзеров",
value=f"{ctx.guild.member_count}",
inline=False)
serverinfoEmbed.add_field(
name="Уровень безопасности",
value=f"{ctx.guild.verification_level}",
inline=False,
)
serverinfoEmbed.add_field(name="Кол-во ролей", value=f"{role_count}", inline=False)
serverinfoEmbed.add_field(name="ID сервера", value=f"{ctx.guild.id}", inline=False)
serverinfoEmbed.add_field(name="Кол-во ролей",
value=f"{role_count}",
inline=False)
serverinfoEmbed.add_field(name="ID сервера",
value=f"{ctx.guild.id}",
inline=False)
await ctx.send(embed=serverinfoEmbed)
@ -152,7 +155,9 @@ async def userinfo(ctx, user: nextcord.User):
username = user.name
avatar = user.avatar.url
await ctx.send(f"ID: {user_id} | NICK: {username}\n{avatar}")
print(f"[Logs:utils] Информация о {username} была выведена | {PREFIX}userinfo")
print(
f"[Logs:utils] Информация о {username} была выведена | {PREFIX}userinfo"
)
@bot.command()
@ -167,19 +172,16 @@ class Confirm(nextcord.ui.View):
self.value = None
@nextcord.ui.button(label="Да", style=nextcord.ButtonStyle.danger)
async def confirm(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
async def confirm(self, button: nextcord.ui.Button,
interaction: nextcord.Interaction):
await interaction.response.send_message(
"https://github.com/CreeperXP/xpyct_bot", ephemeral=True
)
"https://github.com/CreeperXP/xpyct_bot", ephemeral=True)
self.value = True
self.stop()
@nextcord.ui.button(label="Нет", style=nextcord.ButtonStyle.blurple)
async def cancel(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
async def cancel(self, button: nextcord.ui.Button,
interaction: nextcord.Interaction):
await interaction.response.send_message("Ну ладно :(", ephemeral=True)
self.value = False
self.stop()
@ -208,8 +210,11 @@ async def send_m(ctx, member: nextcord.Member, *, text):
user_name = author.name
develop = "CreeperXP"
if user_name == develop:
await member.send(f"От {ctx.author.name}:", embed=nextcord.Embed(description=text))
print(f"[Logs:utils] Сообщение от {ctx.author.name} было отправлено {member.name} | {PREFIX}send_m")
await member.send(f"От {ctx.author.name}:",
embed=nextcord.Embed(description=text))
print(
f"[Logs:utils] Сообщение от {ctx.author.name} было отправлено {member.name} | {PREFIX}send_m"
)
else:
await ctx.send("Ты не разработчик бота!")
time.sleep(7)
@ -220,6 +225,7 @@ async def send_m(ctx, member: nextcord.Member, *, text):
async def mute(ctx):
await ctx.send(file=nextcord.File("leopold-vd.mp4"))
@bot.command() ## Стандартное объявление комманды
async def load(ctx, extensions): ## объявление функции
bot.load_extension(f'cogs.{extensions}') ## загрузка доплонений
@ -231,6 +237,7 @@ async def unload(ctx, extensions):
bot.unload_extension(f"cogs.{extensions}")
await ctx.send('unloaded')
@bot.command()
async def reload(ctx, extensions):
bot.unload_extension(f"cogs.{extensions}") # отгружаем ког
@ -242,6 +249,5 @@ for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
bot.load_extension(f"cogs.{filename[:-3]}")
keep_alive()
bot.run(os.getenv("DISCORD_TOKEN"))