Recherche avancée

Médias (0)

Mot : - Tags -/xmlrpc

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (65)

  • Configurer la prise en compte des langues

    15 novembre 2010, par

    Accéder à la configuration et ajouter des langues prises en compte
    Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
    De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
    Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)

  • L’utiliser, en parler, le critiquer

    10 avril 2011

    La première attitude à adopter est d’en parler, soit directement avec les personnes impliquées dans son développement, soit autour de vous pour convaincre de nouvelles personnes à l’utiliser.
    Plus la communauté sera nombreuse et plus les évolutions seront rapides ...
    Une liste de discussion est disponible pour tout échange entre utilisateurs.

  • Des sites réalisés avec MediaSPIP

    2 mai 2011, par

    Cette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
    Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.

Sur d’autres sites (6495)

  • Discord music bot doesn't play songs

    9 octobre 2023, par Gam3rsCZ

    I have made myself a discord bot that also plays music(it's only for my server so strings with messages are in Czech, but code is in English).
Bot worked a while ago but now it stopped, and I don't know where the problem is

    


    I'm getting these errors : HTTP error 403 Forbidden Server returned 403 Forbidden (access denied) and
C :\Users\Me\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\player.py:711 : RuntimeWarning : coroutine 'music_cog.play_next' was never awaited
self.after(error)
RuntimeWarning : Enable tracemalloc to get the object allocation traceback
[2023-10-09 16:23:47] [INFO ] discord.player : ffmpeg process 17496 successfully terminated with return code of 1.
INFO : ffmpeg process 17496 successfully terminated with return code of 1.

    


    My code is :

    


    import discord
from discord.ext import commands
from yt_dlp import YoutubeDL

class music_cog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

        self.is_playing = False
        self.is_paused = False
        self.current = ""

        self.music_queue = []
        self.YDL_OPTIONS = {"format": "m4a/bestaudio/best", "noplaylist": "True"}
        self.FFMPEG_OPTIONS = {"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5", "options": "-vn"}

        self.vc = None

    def search_yt(self, item):
        with YoutubeDL(self.YDL_OPTIONS) as ydl:
            try:
                info = ydl.extract_info("ytsearch:%s" % item, download=False)["entries"][0]
            except Exception:
                return False
        info = ydl.sanitize_info(info)
        url = info['url']
        title = info['title']
        return {'title': title, 'source': url}

    async def play_next(self):
        if len(self.music_queue) > 0:
            self.is_playing = True
            self.current = self.music_queue[0][0]["title"]
            m_url = self.music_queue[0][0]["source"]

            self.music_queue.pop(0)

            await self.vc.play(discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e:  self.play_next())
        else:
            self.is_playing = False

    async def play_music(self, ctx):
        try:
            if len(self.music_queue) > 0:
                self.is_playing = True
                m_url = self.music_queue[0][0]["source"]

                if self.vc == None or not self.vc.is_connected():
                    self.vc =  await self.music_queue[0][1].connect()

                    if self.vc == None:
                        await ctx.send("Nepodařilo se připojit do hlasového kanálu.")
                        return
                else:
                    await self.vc.move_to(self.music_queue[0][1])

                self.current = self.music_queue[0][0]["title"]
                self.music_queue.pop(0)

                self.vc.play(discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next())
            else:
                self.is_playing = False

        except:
            print("Something went wrong")
            await ctx.send(content="Něco se pokazilo")

    @commands.command(name="play", help="Plays selected song from YouTube")
    async def play(self, ctx, *args):
        query = " ".join(args)

        voice_channel = ctx.author.voice.channel
        if voice_channel is None:
            await ctx.send("Připojte se do hlasového kanálu!")
        elif self.is_paused:
            self.vc.resume()
        else:
            song = self.search_yt(query)
            if type(song) == type(True):
                await ctx.send("Písničku se nepodařilo stáhnout. Špatný formát, možná jste se pokusili zadat playlist nebo livestream.")
            else:
                await ctx.send("Písnička přidána do řady.")
                self.music_queue.append([song, voice_channel])

                if self.is_playing == False:
                    await self.play_music(ctx)
                    self.is_playing = True

    @commands.command(name="pause", aliases=["p"], help="Pauses the BOT")
    async def pause(self, ctx, *args):
        if self.is_playing:
            self.is_playing = False
            self.is_paused = True
            self.vc.pause()
            await ctx.send(content="Písnička byla pozastavena.")
            
        elif self.is_paused:
            self.is_playing = True
            self.is_paused = False
            self.vc.resume()
            await ctx.send(content="Písnička byla obnovena.")

    @commands.command(name="resume", aliases=["r"], help="Resumes playing")
    async def resume(self, ctx, *args):
        if self.is_paused:
            self.is_paused = False
            self.is_playing = True
            self.vc.resume()
            await ctx.send(content="Písnička byla obnovena.")

    @commands.command(name="skip", aliases=["s"], help="Skips current song")
    async def skip(self, ctx, *args):
        if self.vc != None and self.vc:
            self.vc.stop()
        await self.play_next()
        await ctx.send(content="Písnička byla přeskočena.")

    @commands.command(name="queue", aliases=["q"], help="Displays song queue")
    async def queue(self, ctx, songs=5):
        retval = ""

        for i in range(0, len(self.music_queue)):
            if i > songs: break
            retval += "    " + self.music_queue[i][0]["title"] + "\n"

        if retval != "":
            retval += "```"
            await ctx.send(content=("```Aktuální fronta:\n" + retval))
        else:
            await ctx.send("Řada je prázdná.")

    @commands.command(name="clear", help="Clears the queue")
    async def clear(self, ctx):
        if self.vc != None and self.is_playing:
            self.vc.stop()
        self.music_queue = []
        await ctx.send("Řada byla vymazána.")

    @commands.command(name="leave", aliases=["dc", "disconnect"], help="Disconnects the BOT")
    async def leave(self, ctx):
        self.is_playing = False
        self.is_paused = False

        if self.vc != None:
            return await self.vc.disconnect(), await ctx.send(content="BOT byl odpojen.")

        else:
            return await ctx.send("BOT není nikde připojen.")
   
    @commands.command(name="current", help="Displays the current song")
    async def current(self, ctx):
        current = self.current
        retval = f"```Právě hraje:\n    {current}```"
        if current != "":
            await ctx.send(retval)
        else:
            await ctx.send("Aktuálně nic nehraje.")


    


    I already tried everything I can think of(which isn't a lot because I suck at programming), and also tried searching for some solution on the internet, but nothing worked.

    


  • The bot doesn't play music (discord.py)

    30 avril 2024, par Naydar

    The code works fine, but when using the command in guild the bot enters the voice channel but doesn't play music, immediately console gives : ffmpeg process 56560 successfully terminated with return code of 3199971767.

    


    import discord
import youtube_dl
import ffmpeg
import requests
from discord.ext import commands

class music(commands.Cog, name = 'music'):
    def __init__(self, bot):
        self.bot = bot

        self.is_playing = False
        self.is_paused = False


        self.music_queue = []
        self.YTDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
        self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn -filter "volume=0.25"'}

        self.voice_client = None
        
    @commands.command(name="play")
    async def play(self, ctx, url):
        if not ctx.message.author.voice:
            await ctx.send("You are not connected to a voice channel.")
            return

        self.voice_channel = ctx.message.author.voice.channel
        if self.voice_client and self.voice_client.is_connected():
            await self.voice_client.move_to(self.voice_channel)
        else:
            self.voice_client = await self.voice_channel.connect()

        api_key = "my_key"
        video_id = url.split("v=")[1]
        api_url = f"https://www.googleapis.com/youtube/v3/videos?part=snippet&id={video_id}&key={api_key}"

        response = requests.get(api_url)
        if response.status_code == 200:
            data = response.json()
            title = data["items"][0]["snippet"]["title"]
            audio_url = f"https://www.youtube.com/watch?v={video_id}"
            self.voice_client.play(discord.FFmpegOpusAudio(audio_url))
            await ctx.send("Now playing: " + title)
        else:
            await ctx.send("Unable to fetch video information.")

async def setup(bot):
    await bot.add_cog(music(bot))


    


    I tried to rewrite some YTDL and FFMPEG options
(tried to replace "noplaylist" option on "False" and terminal sent :
"discord.player : ffmpeg process 51124 successfully terminated with return code of 4294967295").
Also i checked the updates of modules.

    


  • ffmpeg doesn't work, when starting up it doesn't play music, it gives errors

    14 août 2024, par Оля Михеева
    import discord
from discord import FFmpegPCMAudio
import os
import random
from gtts import gTTS
import asyncio

TOKEN="***"
VOICE_CHANNEL_ID=11122224444

class Voice_Bot(discord.Client):
    def __init__(self):
        intents = discord.Intents.default()
        intents.message_content = True
        intents.voice_states=True
        super().__init__(intents=intents)
        print(os.getcwd())
        self.sounds_hello = os.listdir(os.path.join('sounds','hello'))
        self.sounds_bye = os.listdir('sounds\\bye')
        self.sounds = os.listdir('sounds\\nature')

    async def on_ready(self):        
        self.voice_channel = self.get_channel(VOICE_CHANNEL_ID) 
        if self.voice_channel == None:
            print('Не удалось подключиться к голосовому каналу.')
            return
        self.voice_client = await self.voice_channel.connect()
        print('Бот подключен к голосовому каналу')
        await self.text_to_speech("Lets play Guess the Tune")
        
    async def on_message(self,message):
        if message.author==self.user:
            return
        if message.content.startswith("game"):
            await self.text_to_speech("let's start the game guess the melody")
            music=os.listdir("sounds\\music")
            self.melody=random.choice(music)
            await self.play_sound(f"sounds\\music\\{self.melody}")
        elif message.content==self.melody[0:len(self.melody)-4]:
            if (self.voice_client.is_playing()):
                self.voice_client.stop()
            await self.text_to_speech(f"Congratulations, {message.author.name} answered correctly! To continue, type game")
        else:
            if (self.voice_client.is_playing()):
                self.voice_client.stop()
            await self.text_to_speech(f"Unfortunately, {message.author.name} did not guess. To continue, write game")


    async def on_voice_state_update(self,member,before,after):
        if member.id ==self.user.id:
            print('Someone entered or left the voice channel.')
        else:
            try:
                if before.channel == None:
                    print(f'{member.name} entered the voice channel {after.channel}.')
                    await self.play_sound(f'sounds\\hello\\{random.choice(self.sounds_hello)}')
                elif after.channel == None:
                    print(f'{member.name} left the voice channel {before.channel}.')
                    await self.play_sound(f'sounds\\bye\\{random.choice(self.sounds_bye)}')
            except Exception as e:
                print(f"Error in on_voise_state_update: {e}")

    async def text_to_speech(self,text):
        try:
            tts = gTTS(text=text, lang ="en")
            tts.save("text.mp3")
        except Exception as e:
            print(f"Error e: {e}")
        await self.voice_channel.send(text)
        await self.play_sound("text.mp3")

    def play_sound(self,path):
        print(path)
        source=discord.FFmpegPCMAudio(source=path, executable="ffmpeg\\bin\\ffmpeg.exe")
        if (self.voice_client.is_playing()):
            self.voice_client.stop()
        self.voice_client.play(source)                

client = Voice_Bot()
client.run(TOKEN)


    


    [enter image description here](https://i.sstatic.net/ys8Xza0w.jpg)