user = bot.get_user(1234)
print(user.id)
async def play(ctx):
voice_state = ctx.guild.voice_client
if not voice_state:
error = await Song.join_channel(ctx)
if error:
return error
voice_state = ctx.guild.voice_client
if voice_state.is_playing():
return "alreadyPlay"
ids = []
with sqlite3.connect("database.db") as db:
c = db.cursor()
for n, r, a, i, ai, ly, g, p in c.execute("SELECT * FROM songs WHERE guild = ?", (ctx.guild.id,)):
ids.append(i)
if not os.path.isfile(f"songs/{ids[0]}.mp3"):
Song.download_track(ctx, {'id': ids[0]})
voice_state.play(disnake.FFmpegPCMAudio(f"songs/{ids[0]}.mp3"), after=lambda e: Song.init_after(ctx))
voice_state.is_playing()
return None
def init_after(ctx):
asyncio.run(Song.my_after(ctx))
@commands.slash_command(name="akinator",description="Сыграйте в акинатора.")
async def aki(self, ctx):
await ctx.response.defer()
aki = Akinator(
child_mode=False,
theme=Theme.from_str('characters')
)
first_queston = aki.start_game()
stats = True
component = [
disnake.ui.Button(label="Да",style=disnake.ButtonStyle.success,custom_id="Yes"),
disnake.ui.Button(label="Нет",style=disnake.ButtonStyle.danger,custom_id="No"),
disnake.ui.Button(label="Я не знаю",style=disnake.ButtonStyle.success,custom_id="Idk")
]
def check(msg):
return msg.author.id == ctx.author.id
first_queston = translator.translate(first_queston, dest="ru")
await ctx.send(embed=disnake.Embed(title="Вопрос 1..",description=first_queston.text,color=0x228b22), components=component)
while aki.progression <= 80 and stats:
try:
btn = await bot.wait_for("button_click", check=check, timeout=90)
#if btn.component.custom_id
answer = Answer.from_str(btn.component.custom_id)
aki.answer(answer)
await btn.response.defer()
await ctx.edit_original_response(embed=disnake.Embed(title="Очередной вопрос...",description=translator.translate(aki.question, dest="ru").text, color=0x228b22), components=component)
except asyncio.TimeoutError:
await ctx.send(embed=disnake.Embed(title="Игра закончена!",description="Слишком долго не было взаимодействия с кнопками!"))
stats = False
win = aki.win()
if win:
await ctx.edit_original_response(embed=disnake.Embed(title=f"Это {translator.translate(win.name, dest='ru').text}!",description=translator.translate(win.description, dest="ru").text,color=0x228b22).set_image(url = win.absolute_picture_path), components=None)
stats = False
@slash_command(name="join",description="Подключить бота")
async def _join(self, ctx: commands.Context):
"""Подключается к голосовому каналу."""
ctx.voice_state = self.get_voice_state(ctx)
await ctx.reply(..., type=5)
destination = ctx.author.voice.channel
if ctx.voice_state.voice:
await ctx.voice_state.voice.move_to(destination)
return
ctx.voice_state.voice = await destination.connect()
await channel.set_permissions(ctx.author,speak=True,send_messages=True,read_message_history=True,read_messages=True)
@bot.command(name='clear')
async def _clear(self, ctx, amount:int):
messages = await ctx.channel.purge(limit = amount + 1)
await ctx.send(f"{len(messages)} сообщений было очищено!")
bot.add_command('clear')
@commands.bot_has_permissions(manage_messages=True)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.BotMissingPermissions):
await ctx.reply(embed = discord.Embed(title=f'Ошибка',description=f'Извини, но у меня нет прав!', colour = discord.Color.red()))