Ответы пользователя по тегу Боты
  • Почему бот не присылает картинку?

    @s4q
    http://api.nekos.fun:8080/api/kiss возвращает
    {"image": "https://nekos.fun/storage/kiss/kiss_131.gif"}
    , а вы пытаетесь получить ссылку link

    @bot.command()
    async def neko(ctx):
        response = requests.get('http://api.nekos.fun:8080/api/kiss').json()
    
        embed = discord.Embed(color = 0xff9900, title = 'Кишка')
        embed.set_image(url = response['image'])
        await ctx.send(embed = embed)
    Ответ написан
  • Как отправить сообщение от лица бота discord?

    @s4q
    Разве не очевидно? API не смог получить такой канал.
    Ответ написан
    5 комментариев
  • Discord.py Сохранение mp3 файла на хостинге?

    @s4q
    Ниже код. Перед запуском нужно установить на хостинг FFMpeg (не pip), youtube-dl (pip), PyNaCl (pip) и написать команду "pip install discord.py[voice]".
    Это полный код для проигрывания музыки, включая join и leave.

    import os
    from discord.utils import get
    import youtube_dl
    
    # Ржака и другие Voice Chat
    
    # Join
    @client.command()
    async def join(ctx):
        global voice
        channel = ctx.message.author.voice.channel
        voice = get(client.voice_clients, guild = ctx.guild)
    
        if voice and voice.is_connected():
            await voice.move_to(channel)
        else:
            voice = await channel.connect()
            await ctx.send(f'Бот присоединился к каналу: {channel}')
    
    # Leave
    @client.command()
    async def leave(ctx):
        channel = ctx.message.author.voice.channel
        voice = get(client.voice_clients, guild=ctx.guild)
    
        if voice and voice.is_connected():
            await voice.disconnect()
        else:
            voice = await channel.connect()
            await ctx.send(f'Бот отключился от канала: {channel}')
    
    # Музло
    @client.command()
    async def play(ctx, url : str):
        song_there = os.path.isfile('song.mp3')
    
        try:
            if song_there:
                os.remove('song.mp3')
                print('[log] Старый файл удален')
        except PermissionError:
            print('[log] Не удалось удалить файл')
    
        await ctx.send('Пожалуйста, ожидайте. Файл обрабатывается.')
    
        voice = get(client.voice_clients, guild = ctx.guild)
    
        ydl_opts = {
            'format' : 'bestaudio/best',
            'postprocessors' : [{
                'key' : 'FFmpegExtractAudio',
                'preferredcodec' : 'mp3',
                'preferredquality' : '192'
            }],
        }
    
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            print('[log] Загружаю музыку...')
            ydl.download([url])
    
        for file in os.listdir('./'):
            if file.endswith('.mp3'):
                name = file
                print(f'[log] Переименовываю файл: {file}')
                os.rename(file, 'song.mp3')
    
        voice.play(discord.FFmpegPCMAudio('song.mp3'), after = lambda e: print(f'[log] {name}, музыка закончила свое проигрывание'))
        voice.source = discord.PCMVolumeTransformer(voice.source)
        voice.source.volume = 0.07
    
        song_name = name.rsplit('-', 2)
        await ctx.send(f'Сейчас проигрывает музыка: {song_name[0]}')
    Ответ написан
    Комментировать