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`')
class Select(discord.ui.Select):
def __init__(self):
options=[
discord.SelectOption(label="Option 1",description="Пункт 1!"),
discord.SelectOption(label="Option 2",description="Пункт 2!"),
discord.SelectOption(label="Option 3",description="Пункт 3!")
]
super().__init__(placeholder="Выбери что-то одно",max_values=1,min_values=1,options=options)
async def callback(self, interaction: discord.Interaction):
if self.values[0] == "Option 1":
await interaction.response.edit_message(content="Вывод при выборе пункта 1")
elif self.values[0] == "Option 2":
await interaction.response.send_message("Вывод при выборе пункта 2")
elif self.values[0] == "Option 3":
await interaction.response.send_message("Вывод при выборе пункта 3")
def check_if_it_is_me(ctx):
return ctx.message.author.id == 85309593344815104
@bot.command()
@commands.check(check_if_it_is_me)
async def only_for_me(ctx):
await ctx.send('I know you!')
from discord.ext import tasks, commands
class MyCog(commands.Cog):
def __init__(self):
self.index = 0
self.printer.start()
def cog_unload(self):
self.printer.cancel()
@tasks.loop(seconds=5.0)
async def printer(self):
print(self.index)
self.index += 1