[NodeJS] Lire plusieurs fichiers audio 1 par 1 dans un salon Vocal Discord

Fermé
Valentin_Kh Messages postés 9 Date d'inscription lundi 20 juillet 2020 Statut Membre Dernière intervention 21 octobre 2020 - 10 oct. 2020 à 16:09
Valentin_Kh Messages postés 9 Date d'inscription lundi 20 juillet 2020 Statut Membre Dernière intervention 21 octobre 2020 - 21 oct. 2020 à 09:18
Bonjour,

Ça fait 1 semaine que je suis bloqué sur un problème, j'essaye de faire lire à mon bot Discord des fichiers audio hébergé localement de sorte à ce qu'il lisent les fichiers 1 par 1

Voilà le bout de code que j'ai écrit mais qui marche pas :
    const dispatcher0 = connection.play(`../../assets/sounds/code/start.mp3`)
    if (dispatcher0.on("end")) const dispatcher1 = connection.play(`../../assets/sounds/code/${args[0].charAt(0)}.mp3`)
    if (dispatcher1.on("end")) const dispatcher2 = connection.play(`../../assets/sounds/code/${args[0].charAt(1)}.mp3`)
    if (dispatcher2.on("end")) const dispatcher3 = connection.play(`../../assets/sounds/code/${args[0].charAt(2)}.mp3`)
    if (dispatcher3.on("end")) const dispatcher4 = connection.play(`../../assets/sounds/code/${args[0].charAt(3)}.mp3`)
    if (dispatcher4.on("end")) const dispatcher5 = connection.play(`../../assets/sounds/code/${args[0].charAt(4)}.mp3`)
    if (dispatcher5.on("end")) const dispatcher6 = connection.play(`../../assets/sounds/code/${args[0].charAt(5)}.mp3`)
    if (dispatcher6.on("end")) voiceChannel.leave()

Je suis sur NodeJS 12
A voir également:

1 réponse

Alvin1614 Messages postés 107 Date d'inscription lundi 24 avril 2017 Statut Membre Dernière intervention 22 décembre 2021 4
Modifié le 17 oct. 2020 à 16:19
Bonjour,

Essaye peut-être comme ceci...

const stream = [
"../../assets/sounds/code/start.mp3",
`../../assets/sounds/code/${args[0].charAt(0)}.mp3`,
`../../assets/sounds/code/${args[0].charAt(1)}.mp3`,
`../../assets/sounds/code/${args[0].charAt(2)}.mp3`,
`../../assets/sounds/code/${args[0].charAt(3)}.mp3`,
`../../assets/sounds/code/${args[0].charAt(4)}.mp3`,
`../../assets/sounds/code/${args[0].charAt(5)}.mp3`,
]

var dispatcher = connection.play(stream[0])
var STREAMn = 1

dispatcher.on('end', () => {
if (STREAMn <= 5) {
dispatcher = connection.play(stream[STREAMn])
STREAMn++
}
})


Je précise que j'ai pas testé^^. C'est peut-être la solution... Si tu as encore besoin d'aide, si ça ne marche pas, n'hésite pas à me contacter ;)

Bonne journée,
0
Valentin_Kh Messages postés 9 Date d'inscription lundi 20 juillet 2020 Statut Membre Dernière intervention 21 octobre 2020
21 oct. 2020 à 09:18
Bonjour Alvin1614,
Désolé pour ma réponse tardive j'était très occupé.
En testant votre code 2 messages d'erreur sont apparu sur ma console
(node:20888) UnhandledPromiseRejectionWarning: ReferenceError: connection is not defined
at Object.module.exports.run (F:\Bot Discord\Among_Us\commands\game\voicecode.js:30:26)
at module.exports (F:\Bot Discord\Among_Us\events\client\message.js:39:13)
at Client.emit (events.js:327:22)
at MessageCreateAction.handle (F:\Bot Discord\Among_Us\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (F:\Bot Discord\Among_Us\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (F:\Bot Discord\Among_Us\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (F:\Bot Discord\Among_Us\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (F:\Bot Discord\Among_Us\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (F:\Bot Discord\Among_Us\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
(node:20888) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:20888) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
0