#javascript #visual-studio-code #discord.js #bots
Вопрос:
Я пишу замену бота discord для groovy, так как он был забанен, но каждый раз, когда я пытаюсь выполнить команду-play, бот показывает ошибку (фото ошибки связано) Я не знаю, что я сделал не так, может кто-нибудь, пожалуйста, помогите?! (код также связан) Я изменил код бота. Я перепробовал много вещей, которые нашел в Интернете, но не знаю, как мне помочь. кстати, это музыкальный бот. спасибо вам:)
Ошибка в том, что он не может прочитать «выполнить» как команду.
Основной код-
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"]});
const prefix = '-';
const fs = require('fs');
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', () => {
console.log('Groovy is back!');
});
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 === 'ping'){
message.channel.send('pong!');
} else if (command == 'youtube'){
message.channel.send('https://www.youtube.com/channel/UCwCs6NRBb9XaEKa787TyrQg')
} else if (command == 'groovy'){
message.channel.send('https://groovy.bot')
} else if (command === 'leave') {
client.commands.get('leave').execute(message, args);
} else if (command === 'play') {
client.commands.get('play').execute(message, args);
}
});
client.login('ODg3NDU1NjY5NjkzODU3Nzky.EUFZwf.ZK8TaB2tIVdww8hzPFQe6NBbRzk');
-игровой код:
const ytdl = require('ytdl-core');
const ytSearch = require('yt-search');
module.exports = {
name: 'play',
description: 'Joins and plays a video from youtube',
async execute(message, args) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send('You need to be in a channel to execute this command!');
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) return message.channel.send('You dont have the correct permissins');
if (!permissions.has('SPEAK')) return message.channel.send('You dont have the correct permissins');
if (!args.length) return message.channel.send('You need to send the second argument!');
const validURL = (str) =>{
var regex = /(http|https)://(w :{0,1}w*)?(S )(:[0-9] )?(/|/([w#!:.? =amp;%!-/]))?/;
if(!regex.test(str)){
return false;
} else {
return true;
}
}
if(validURL(args[0])){
const connection = await voiceChannel.join();
const stream = ytdl(args[0], {filter: 'audioonly'});
connection.play(stream, {seek: 0, volume: 1})
.on('finish', () =>{
voiceChannel.leave();
message.channel.send('leaving channel');
});
await message.reply(`:thumbsup: Now Playing ***Your Link!***`)
return
}
const connection = await voiceChannel.join();
const videoFinder = async (query) => {
const videoResult = await ytSearch(query);
return (videoResult.videos.length > 1) ? videoResult.videos[0] : null;
}
const video = await videoFinder(args.join(' '));
if(video){
const stream = ytdl(video.url, {filter: 'audioonly'});
connection.play(stream, {seek: 0, volume: 1})
.on('finish', () =>{
voiceChannel.leave();
});
await message.reply(`:thumbsup: Now Playing ***${video.title}***`)
} else {
message.channel.send('No video results found');
}
}
}
-оставьте код:
module.exports = {
name: 'leave',
description: 'stop the bot and leave the channel',
async execute(message, args) {
const voiceChannel = message.member.voice.channel;
if(!voiceChannel) return message.channel.send("You need to be in a voice channel to stop the music!");
await voiceChannel.leave();
await message.channel.send('Leaving channel :smiling_face_with_tear:')
}
}
Комментарии:
1. Удалите свой токен бота с вашего вопроса как можно скорее!
2. @Zero простое удаление не поможет. Пожалуйста, восстановите свой токен. Его все еще можно найти на странице прошлых правок!
3. «не работает» — это недостаточная информация. Какую отладку вы провели? Я предполагаю, что фактическая ошибка такова
execute is not a function
. Пожалуйста, укажите ошибку, чтобы помочь нам