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

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

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

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

Q&A

解決済

1回答

1274閲覧

Discord.jsで投稿者を取得

drgcghffjd

総合スコア10

Node.js

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

0グッド

0クリップ

投稿2021/07/29 23:01

編集2021/07/30 00:50

前提・実現したい

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 fs = require("fs"); const ytdl = require('ytdl-core'); const client = new discord.Client(); //ログに通知 client.on('ready', () => { console.log('正常に起動しました'); }); //音楽 client.on('message', async message => { if (message.content.startsWith('b.pplay') && message.guild) { message.delete({ timeout: 0 }) const url = message.content.split(' ')[1] if (!ytdl.validateURL(url)) return message.reply( {embed: { color: 0x0fc0303, description: 'エラー\nURLに問題があります' }} ); const channel = message.member.voice.channel if (!channel) return message.reply( {embed: { color: 0x0fc0303, description: 'エラー\nボイスチャンネルに接続してください' }} ); const connection = await channel.join() const stream = ytdl(ytdl.getURLVideoID(url), { filter: 'audioonly' }) const dispatcher = connection.play(stream) const msg = await message.channel.send( {embed: { color: 0x0032cfc, description: `再生\n再生中です\nタイトル\n${videos[ 0 ].title}` }} ); dispatcher.once('finish', () => { channel.leave() msg.edit( {embed: { color: 0x0fc0303, description: '切断\n再生が終了したためボイスチャンネルから切断します' }} ); }) } }) //接続時に必要 client.login(process.env.TOKEN);

試したこと

`投稿者\n[${videos[ 0 ].uploader}` で試してみましたが無理でした

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

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

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

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

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

guest

回答1

0

ベストアンサー

そもそもvideosが定義されていません。

yt-searchなどを使う方法があります。

js

1//24時間起動に必要(web) 2const http = require('http'); 3http.createServer(function (req, res) { 4 res.write("login"); 5 res.end(); 6}).listen(8080); 7 8//起動に必要 9const discord = require("discord.js"); 10const fs = require("fs"); 11const ytdl = require('ytdl-core'); 12const client = new discord.Client(); 13const yts = require("yt-search"); 14 15//ログに通知 16client.on('ready', () => { 17 console.log('正常に起動しました'); 18}); 19 20//音楽 21client.on('message', async message => { 22 if (message.content.startsWith('b.pplay') && message.guild) { 23 message.delete({ timeout: 0 }) 24 const kyoku = message.content.split(' ')[1] 25 const channel = message.member.voice.channel 26 if (!channel) return message.reply( 27 {embed: { 28 color: 0x0fc0303, 29 description: 'エラー\nボイスチャンネルに接続してください' 30 }} 31); 32 const msg = await message.channel.send("検索中です"); 33 const connection = await channel.join() 34 const r = await yts(kyoku); 35 const video = r.videos[0]; 36 const stream = ytdl(ytdl.getURLVideoID(video.url), { filter: 'audioonly' }) 37 const dispatcher = connection.play(stream) 38 msg.edit( 39 {embed: { 40 color: 0x0032cfc, 41 description: `再生\n再生中です\nタイトル\n[${video.title}\n投稿者\n${video.author.name}` 42 }} 43); 44 dispatcher.once('finish', () => { 45 channel.leave() 46 msg.edit( 47 {embed: { 48 color: 0x0fc0303, 49 description: '切断\n再生が終了したためボイスチャンネルから切断します' 50 }} 51); 52 }) 53 } 54 }) 55 56 //接続時に必要 57client.login(process.env.TOKEN);

※yt-searchのインストールを忘れないでください。

bash

1npm install yt-search #npmの場合 2yarn add yt-search #yarnの場合

投稿2021/07/30 01:19

Waki285

総合スコア2014

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

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

drgcghffjd

2021/07/30 01:47

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問