'When I use the -play command,I get an "Uncaught SyntaxError SyntaxError" [duplicate]
I'm trying to make a discord music bot and when I use the -play command which is the only one I've created so far it gives me this error is console
"(node:20336) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)"
which when I do, I get this
Uncaught SyntaxError SyntaxError: Unexpected identifier
at (program) (<eval>/VM46947595:1:8)
as a result, I am very confused
also here's the code
const ytdl = require('ytdl-core');
const ytSearch = require('yt-search');
const { Message } = require('discord.js');
const queue = new Map();
modulue.exports = {
name: 'play',
aliases:['skip', 'stop', 'pause', 'resume'],
cooldown: 0,
description: 'dat jazz baby',
async execute(Message, args, cmd, client, Discord){
const voice_channel = Message.member.voice.channel;
if (!voice_channel) return message.channel.send('you ain\'t in a voice channel dummy');
const permissions = voice_channel.permissionsFor(Message.client.user);
if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) return message.channel.send('can\'t talk');
const server_queue = queue.get(Message.guild.id);
if (Message.content === prefix + play){
if (!args.length) return message.channel.send('no args. You keep this up and Mark Zukerberg could die of ligma');
let song = {};
if (ytdl.validateURL(args[0])){
const song_info = await ytdl.getInfo(args[0]);
song = {title: song_info.videoDetails.title, url: song_info.videoDetails.video_url};
} else {
const video_finder = async (query) => {
const videoresult = await ytSearch(query);
return (videoresult.videos.length > 0) ? videoresult.videos[0] : null;
}
const song_info = await video_finder(args.join(' '));
if (video){
song = title; video.title, url; video.url }
else {
return Message.channel.send('damn so no maidens or vidjas');
}
}
if (!server_queue){
const queue_constructor = {
textChannel: message.channel,
voiceChannel: voice_channel,
connection: null,
songs: [],
}
queue.set(message.guild.id, queue_constructor);
queue_constructor.songs.push.push(song)
try {
const connection = await voice_channel.join();
queue_constructor.connection = connection;
play(message.guild, queue_constructor.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
message.channel.send('I fell and I can\'t get up\(try again\)');
throw err; // this will throw the error to the console
}
} else {
server_queue.song.push(song);
return message.channel.send(`${song.title} has been added to the queue`);
}
}
}
}
const video_player = async (guild, song) => {
const server_queue = queue.get(guild.id);
if (!song) {
server_queue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const stream = ytdl(song.url, {filter: 'audioonly'});
song_queue.connection.play(stream, { Seek: 0, volume: 0.5})
.on(finish, () => {
server_queue.songs.shift();
video_player(guild, server_queue.songs[0]);
})
}
I didn't exactly expect it to work, but seeing as I'm pretty new to coding I'm kinda helpless
Solution 1:[1]
The error shown in your message is not an error, it's a module DeprecationError. I'm pretty sure that's not causing the problem. The real error is the SyntaxError.
Is your code in Typescript (TS)?
(ytdl-core is a node js dependency, so you have to use require unless you are using TS)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Science done right |
