当我的个人服务器的文本通道中写入一个单词时,希望机器人播放预定的音频文件。遇到麻烦,因为它正在阅读消息,运行代码,但当我真的在语音频道时却找不到我。有加入权限,不知道为什么它不起作用。
编辑:新代码
var Discord = require('discord.js');
const { waitForDebugger } = require('inspector');
var bot = new Discord.Client();
var isReady = true;
const path = require('path');
const ytdl = require('ytdl-core');
bot.on('guildMemberAdd', guildMember =>{
let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'Average Bread');
guildMember.roles.add(welcomeRole);
console.log('Role Assigned');
});
bot.once('ready', () => {
console.log('Bot is Online');
});
bot.on('message', message => {
const args = message.content.split(/ +/);
const command = args.shift().toLowerCase();
var VC = message.member.voice.channel;
if (command === "join") {
if (!VC) return message.reply("You are not in a voice channel.")
VC.join()
.then(connection => {
message.channel.send('Joining Channel');
var stream = ytdl('https://www.youtube.com/watch?v=U06jlgpMtQs')
connection.play(stream, {seek: 0, volume: 1});
console.log('Joining')
})
.catch(console.error);
}
else if (command === "leave") {
VC.leave()
message.channel.send('Leaving channel');
console.log('Leaving');
}});
bot.login('token');