質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Q&A

解決済

1回答

1936閲覧

Discord.jsの音楽機能について

drgcghffjd

総合スコア10

Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

0グッド

0クリップ

投稿2021/09/22 16:23

前提・実現したい

Discord.jsの音楽機能で公開されている動画、限定公開の動画も再生するようにしたいです。

発生している問題

Discord.jsで音楽機能が完成したので試していたら公開されている動画は再生したのですが、限定公開の場合は再生しません。

ソースコード

//24時間起動に必要(web) const http = require('http'); http.createServer(function (req, res) { res.write("login"); res.end(); }).listen(8080); //起動に必要 const discord = require("discord.js"); const ytdl = require('ytdl-core'); const client = new discord.Client(); //音楽 client.on('message', async message => { if (message.content.startsWith("b.play")){ const channel = message.member.voice.channel if (!channel) return message.reply( {embed: { color: 0x0032cfc, description: 'エラー\nボイスチャンネルに接続して下さい' }} ); const connection = await channel.join() const msg = await message.channel.send( {embed: { color: 0x0032cfc, description: 'ボイスチャンネルに接続してます...' }} ); const AKB = message.content.split(" ").slice(1).join(" ") if (!AKB) return message.channel.send( {embed: { color: 0x0032cfc, title: 'エラー', description: '曲名を指定して下さい' }} ); const yts = require( 'yt-search' ) msg.edit( {embed: { color: 0x0032cfc, description: '検索中...' }} ); yts( AKB, function ( err, r ) { const videos = r.videos const playlists = r.playlists || r.lists const channels = r.channels || r.accounts msg.edit( {embed: { color: 0x0fc0303, description: '以下を再生します' }} ); const video = r.videos[0]; const stream = ytdl(ytdl.getURLVideoID(video.url), { filter: 'audioonly' }) const dispatcher = connection.play(stream) message.channel.send( {embed: { color: 0x0fc0303, description: `タイトル\n[${videos[ 0 ].title}](${videos[ 0 ].url})\n投稿者\n[${videos[ 0 ].author.name}](${videos[ 0 ].author.url})\n再生回数\n${videos[0].views}回\n再生時間\n${videos[ 0 ].duration}` }} ); })}}) //接続時に必要 client.login(process.env.TOKEN);

試したこと

const stream = ytdl(ytdl.getURLVideoID(video.url), { filter: 'audioonly' }) のところを const stream = ytdl(ytdl.getURLVideoID(url), { filter: 'audioonly' }) 変えてみましたが出来ませんでした

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ytsは公開動画しか検索できないからです。
YouTubeの動画かどうか判定してytsを使うかどうか判断させる必要があります。
判断の仕方はいろいろあるので、自分で考えてみてください。

投稿2021/09/23 00:57

Waki285

総合スコア2014

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

drgcghffjd

2021/09/23 01:09

ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問