【发布时间】:2021-11-21 17:27:12
【问题描述】:
试图制作一个只播放一个链接的简单音乐机器人,但它没有连接到语音通道,它没有给出任何错误,所以除了输入我的所有代码之外我什么也做不了. 这是我的 Main.js
const {Intents} = require('discord.js');
const Discord = require('discord.js');
const botIntents = [ Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MEMBERS];
const client = new Discord.Client({ intents: botIntents });
const prefix = '-';
const fs = require('fs');
const teo = "<@---------->";
const aime = "<@------------>";
const pagliac = "Di di no alla vita sociale! Ogni giorno migliaia di gamer perdono i propri amici per questa Vita sociale, Non si sa cosa sia pero se donate una piccola somma di: 4 reni, tua madre e forse anche tua sorella";
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', async () =>{
console.log('Ready!');
client.user.setActivity('Tua madre', { type: 'PLAYING' });
})
client.on ('message', message=>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'embed'){
client.commands.get('embed').execute(message, args, Discord, client);
} else if (command === 'pong'){
message.channel.send('Aime e un pagliaccio, giochiamo a the forest');
} else if (command === 'teo'){
for (var i=0; i<5; i++){
message.channel.send(teo);
}
} else if (command === 'aime'){
for (let s=0; s<5; s++){
message.channel.send(aime);
message.channel.send(pagliac);
}
} else if (command === 'clear'){
client.commands.get('clear').execute(message, args);
} else if (command === 'ping'){
message.channel.send(`Pingazzo pazzo di: ${Date.now() - message.createdTimestamp}ms. La latenza delle api ${Math.round(client.ws.ping)}ms`);
} else if (command === 'acqua'){
const siuum = new Discord.MessageEmbed()
.setColor('#0011FF')
.setTitle('Marmellata')
.setDescription('marmellata')
const sus = message.mentions.users.first();
sus.send({embeds: [siuum]});
} else if(command === 'bully'){
client.commands.get('bully').execute(message)
} else if(command === 'aimesus')
client.commands.get('aimesus').execute(message)
});
这是我的音乐机器人命令,我认为它是正确的,因为我已经在这里寻求帮助。
const ytdl = require('ytdl-core');
module.exports ={
name:'aimesus',
description:'aaaaaaaaaaaam',
execute(message, args){
const { joinVoiceChannel, createAudioPlayer, createAudioResource, generateDependencyReport, VoiceConnectionStatus } = require('@discordjs/voice');
const url = 'https://www.youtube.com/watch?v=NevKVKbCNy4&ab_channel=NTDM'
const stream = ytdl(url, {filter: 'audioonly'});
const player = createAudioPlayer();
const resource = createAudioResource(stream);
const connection = joinVoiceChannel({
channelId: message.channelid,
guildId: message.guildid,
adapterCreator: message.guild.voiceAdapterCreator
})
connection.subscribe(player);
player.play(resource);
console.log(generateDependencyReport());
}
}
【问题讨论】:
-
也许你混淆了它,但你真的用你的机器人令牌登录了吗?
-
但是,下次避免发布带有可能“不太合适”的 cmets 和字符串的问题。毕竟这是一个拥有codes of conduct 的专业网站。
标签: javascript discord discord.js