[英]Play audio file from a commands in Discord.js
I want to play an audio file in my folder from a command on Discord bot, in Discord.js .我想通过 Discord.js 中Discord bot 上的命令播放文件夹中的音频文件。 How should i do?
我应该怎么做? Thanks This is my code:
谢谢这是我的代码:
const Discord = require('discord.js'); const client = new Discord.Client(); var ChannelId = "ID_CHANNEL"; var token = "TOKEN"; client.on("message", (message) => { if(message.content == ";audio"){ /*HERE*/ } });
You'll need to find a voice channel first, for example the one the user typing the command is in (if any) like this:您需要先找到一个语音通道,例如用户键入命令的通道(如果有),如下所示:
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send("No voice channel.");
Then join the channel and then play your file:然后加入频道,然后播放您的文件:
voiceChannel.join()
.then(connection => {
connection.play('/path/to/yourFile.mp3');
});
You can check what else you can do by reading the docs .您可以通过阅读文档来检查您还能做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.