@bot.event
async def on_slash_command_error(interaction: ApplicationCommandInteraction, error: Exception) -> None:
"""
The code in this event is executed every time a valid slash command catches an error
:param interaction: The slash command that failed executing.
:param error: The error that has been faced.
"""
pass
@client.event
async def on_voice_state_update(member, before, after):
# присоединение к каналу
if before.channel is None and after.channel is not None:
start_log(member.id, after.channel.id)
# покинул канал
elif before.channel is not None and after.channel is None:
end_log(member.id, before.channel.id)
# перешел в другой канал
elif before.channel is not None and after.channel is not None:
end_log(member.id, before.channel.id)
start_log(member.id, after.channel.id)
@commands.cooldown(1, 60, commands.BucketType.user)
async def idea(ctx,*, idea=None):
if is_admin(ctx.author): # подставить свой способ проверки
idea.reset_cooldown(ctx)
await ctx.channel.send("**На каждый вопрос дается 60 секунд на ответ!**")
await ctx.channel.send(f"Наберите название ивента")
try:
event = await self.bot.wait_for('message', check=check, timeout = 60.0)
except asyncio.TimeoutError:
await ctx.channel.send('TimeoutError. Повторите команду')
# дальше по аналогии
if role := member.guild.get_role(418187634689139935):
async def on_member_join(member):
role = discord.utils.get(member.guild.roles, name="Имя роли") #или id = role_id
await member.add_roles(role)
loop = True
while loop:
res = await client.wait_for("button_click")
if res.component.label == "Button1":
embed = Embed(title="Button1", description=f"Вы нажали Button1")
await res.respond(
type=7,
components = []
)
await res.channel.send(embed=embed)
@Cog.listener()
async def on_button_click(self, interaction):
await interaction.respond(content=f"Вы нажали {interaction.component.custom_id}")
from discord.ext import tasks
@bot.event
async def on_ready():
test_task.start()
@tasks.loop(minutes=1.0)
async def test_task():
#твой код
@bot.event
async def on_voice_state_update(member, before, after):
voice = discord.utils.get(bot.voice_clients, guild=member.guild)
if voice and voice.is_connected():
if len(voice.channel.members) == 1:
await voice.disconnect()
@commands.command(name="cooldown_test")
@commands.cooldown(1, 30, commands.BucketType.user)
async def cooldown_test(self, ctx, command=None):
if command is None:
await ctx.send('В этой ветке кулдаун будет сброшен и команду можно вызвать еще раз')
self.cooldown_test.reset_cooldown(ctx)
else:
await ctx.send('В этой ветке будет установлен кулдаун для пользователя 30 секунд, '
'при повторном вызове будет ошибка `commands.errors.CommandOnCooldown`')