discordのbotについての質問です。
現在とあるサイトのコードを参考に、discord.jsで音楽botを作っているのですが、音楽の再生を行う段階で、
const dispatcher = connetction.play(stream) is not a function
...................................................↑
と言われてしまいます。
問題の箇所は、roop.js内にあります
コード
javascript(main.js)
1// Discord bot パッケージの読み込み 2const { Embed } = require("@discordjs/builders"); 3const discord = require("discord.js"); 4const ytdl = require('ytdl-core') 5const roop = require('./roop.js') 6 7// Discord Version Check 8console.log("Discord.js Version" + discord.version); 9 10// *client のインスタンス作成 11const client = new discord.Client(); 12 13// トークン設定 14const token = ("TOKEN"); 15 16// ready時の処理 17client.on("ready", () => { 18 console.log(`${client.user.tag} にログインしました。`) 19}); 20 21prefix1 = ".play" 22prefix2 = ".down" 23prefix3 = ".list" 24url = "fail" 25nowPlay = null 26li1 = null 27li2 = null 28li3 = null 29starter = false 30VC = null 31 32 33client.on("message", async message=> { 34 if(message.author.bot) return 35 if(message.content.startsWith(prefix1)){ 36 37 url = message.content.split(' ')[1] 38 if(!url){ 39 message.channel.send( 40 {embed: { 41 title: "ERROR", 42 description: "URLを入力してください!" 43 } 44 } 45 ) 46 return 47 } 48 49 if(nowPlay == null){ 50 starter = true 51 nowPlay = url 52 message.channel.send( 53 {embed: { 54 title: ":musical_note: 再生", 55 description: url+"を再生します" 56 } 57 } 58 ) 59 }else if(li1 == null){ 60 li1 = url 61 message.channel.send( 62 {embed: { 63 title: ":white_check_mark: 追加", 64 description: url+"をリスト1に追加します" 65 } 66 } 67 ) 68 }else if(li2 == null){ 69 li2 = url 70 message.channel.send( 71 {embed: { 72 title: ":white_check_mark: 追加", 73 description: url+"をリスト2に追加します" 74 } 75 } 76 ) 77 }else if(li3 == null){ 78 li3 = url 79 message.channel.send( 80 {embed: { 81 title: ":white_check_mark: 追加", 82 description: url+"をリスト3に追加します" 83 } 84 } 85 ) 86 }else return message.channel.send( 87 {embed: { 88 title: "ERROR", 89 description: "リストに空きがありません。\n曲の再生が終わってからもう一度試してください。" 90 } 91 } 92 ) 93 } 94 else if(message.content.startsWith(prefix2)){ 95 nowPlay = null 96 li1 = null 97 li2 = null 98 li3 = null 99 VC.leave() 100 message.channel.send("終了") 101 }else if(message.content.startsWith(prefix3)){ 102 message.channel.send( 103 {embed:{ 104 title: "リスト" 105 }, 106 fields: [ 107 { 108 name: "playing", 109 value: nowPlay 110 }, 111 { 112 name: ":one:", 113 value: li1 114 }, 115 { 116 name: ":two:", 117 value: li2 118 }, 119 { 120 name: ":three:", 121 value: li3 122 } 123 ] 124 } 125 ) 126 } else return 127 128 if(!starter == true) return 129 130 if(!ytdl.validateURL(url)) return 131 message.channel.bulkDelete(1) 132 message.channel.send( 133 {embed: { 134 title: "ERROR", 135 description: "正しいURLを入力してください!" 136 }, 137 } 138 ) 139 140 VC = message.member.voice.channel 141 if(!VC) return 142 message.channel.send( 143 {embed: { 144 title: "ERROR", 145 description: "先にVCに入ってください!" 146 }, 147 } 148 ) 149 150 151 connection = VC.join() 152 153 roop(client) 154}) 155client.login("TOKEN")
javascript(roop.js)
1// Discord bot パッケージの読み込み 2const { Embed } = require("@discordjs/builders"); 3const discord = require("discord.js"); 4const ytdl = require('ytdl-core') 5 6 7// *client のインスタンス作成 8const client = new discord.Client(); 9 10function roop(client) { 11 const stream = ytdl(ytdl.getURLVideoID(nowPlay), { filter: 'audioonly' }) 12 const dispatcher = connection.play(stream) 13 14 dispatcher.once('finish', () => { 15 const nowPlay = null 16 if (li1 == null) { 17 VC.leave() 18 li1 = null 19 li2 = null 20 li3 = null 21 nowPlay = null 22 } else { 23 nowPlay = li1 24 25 li1 = li2 26 27 li2 = li3 28 li3 = null 29 30 roop(client) 31 } 32 }) 33} 34module.exports = roop
roop.jsは再生の処理だけ別のファイルでやっているので、functionにして外部から読み込んでいます。
どなたか解決方法を教えていただけませんでしょうか。
それと、もうひとつ質問なのですが、コードの一定のポイントまで戻って再び処理を行う方法はありますか?よければついでに教えて頂きたいです。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/29 23:31