Giter VIP home page Giter VIP logo

Comments (13)

bulletsabbath avatar bulletsabbath commented on July 20, 2024 1

oh i accidentally was right :0

from erela.js.

karelkryda avatar karelkryda commented on July 20, 2024

Can you show me your code? @Knatschkopp

from erela.js.

Knatschkopp avatar Knatschkopp commented on July 20, 2024

This is my play command.

const { MessageEmbed } = require('discord.js');
const { Utils } = require("erela.js");
const hook = require('../../utils/hook');

module.exports = {
	name: 'play',
	category: 'music',
	aliases: ['p'],
	description: 'Play a song/playlist or add a song to the queue.',
	cooldown: 5,
	guildOnly: true,
	permissions: ['CONNECT'],
	roles: ['@everyone'],
	args: true,
	usage: '<url|search name>',
	async execute(client, message, cmd, args) {
		const voiceChannel = message.member.voice.channel;
		if (!voiceChannel) return hook.send(message.channel, 'You need to be in a voice channel', {
			name: 'Error',
			icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/caution-512.png',
			delete: 5000,
		});
		if (client.music.players.get(message.guild.id) && voiceChannel.id !== client.music.players.get(message.guild.id).voiceChannel) return hook.send(message.channel, 'You need to be in the same channel as the bot.', {
			name: 'Error',
			icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/caution-512.png',
			delete: 5000,
		});

		const permissions = voiceChannel.permissionsFor(client.user);
		if (!permissions.has('CONNECT')) return hook.send(message.channel, 'I don\'t have permission to join that channel.', {
			name: 'Error',
			icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/caution-512.png',
			delete: 5000,
		});
		if (!permissions.has('SPEAK')) return hook.send(message.channel, 'An error occured.', {
			name: 'Error',
			icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/caution-512.png',
			delete: 5000,
		});

		const player = client.music.create({
			guild: message.guild.id,
			textChannel: message.channel.id,
			voiceChannel: voiceChannel.id,
		});

		player.connect();

		client.music.search(args.join(' '), message.author).then(async res => {
			switch (res.loadType) {
				case 'TRACK_LOADED':
				player.queue.add(res.tracks[0]);
				hook.send(message.channel, `Added \`${res.tracks[0].title}\` \`${res.tracks[0].duration}\` to the queue.`, {
					name: 'Radio',
					icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/music-256.png',
					delete: 10000,
				});
				if (!player.playing && !player.paused && !player.queue.size) player.play();
				break;

				case 'SEARCH_RESULT':
				let index = 1;
				player.queue.add(res.tracks[0]);
				hook.send(message.channel, `Added \`${res.tracks[0].title}\` \`${res.tracks[0].duration}\` to the queue.`, {
					name: 'Radio',
					icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/music-256.png',
					delete: 10000,
				});
				if (!player.playing && !player.paused && !player.queue.size) player.play();
				break;

				case 'PLAYLIST_LOADED':
				res.playlist.tracks.forEach(track => player.queue.add(track));
				const duration = res.playlist.tracks.reduce((acc, cur) => ({duration: acc.duration + cur.duration})).duration;
				hook.send(message.channel, `Adding \`${res.playlist.tracks.length}\` \`${duration}\` tracks in playlist \`${res.playlist.info.name}\` to the queue.`, {
					name: 'Radio',
					icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/music-256.png',
					delete: 10000,
				});
				if (!player.playing && !player.paused && player.queue.totalSize === res.tracks.length) player.play();
				break;

				case 'NO_MATCHES':
				hook.send(message.channel, `No matches found.`, {
					name: 'Radio',
					icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/music-256.png',
					delete: 10000,
				});
				break;
			}
		}).catch(error => console.error(error.message));
	},
};

from erela.js.

karelkryda avatar karelkryda commented on July 20, 2024

Any errors in console?

from erela.js.

Knatschkopp avatar Knatschkopp commented on July 20, 2024

No, i dont get any errors. The reason why i know that the socket closes is because i have this:

.on("socketClosed", player => {
	let selMsgs = client.channels.resolve(player.textChannel).messages.cache.filter(m => m.author.bot && m.author.username === 'Radio' && m.embeds.length === 0);
	let string = `Now playing: **`;
	selMsgs.forEach(msg => {
		if (msg.content.includes(string)) {
			msg.delete();
		}
	});
	hook.send(client.channels.resolve(player.textChannel), 'Bot disconnected.', {
		name: 'Radio',
		icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/music-256.png',
		delete: 10000,
	});
	player.destroy();
});

from erela.js.

karelkryda avatar karelkryda commented on July 20, 2024

Try tu put some console.log() to code

from erela.js.

karelkryda avatar karelkryda commented on July 20, 2024

Try change this
if (!player.playing && !player.paused && !player.queue.size) player.play();
to
if (!player.playing && !player.paused && !player.queue.totalSize) player.play();

and you can

case 'TRACK_LOADED':
case 'SEARCH_RESULT':
**same code here**

from erela.js.

Knatschkopp avatar Knatschkopp commented on July 20, 2024

The

if (!player.playing && !player.paused && !player.queue.totalSize) player.play();

now made it so it wont play anymore at all, what and where exactly do you want me to log?

from erela.js.

karelkryda avatar karelkryda commented on July 20, 2024

i'm pretty sure if you use !player.queue.totalSize it's going to return because it is true

edit: never mind me i'm an idiot

you're right ... my bad it must be .size

from erela.js.

karelkryda avatar karelkryda commented on July 20, 2024

Try to put console.log("SOMETHING") into .on("socketClosed", player => {

from erela.js.

Knatschkopp avatar Knatschkopp commented on July 20, 2024

I found a solution:

let player;
if (!client.music.players.get(message.guild.id)) {
	player = client.music.create({
		guild: message.guild.id,
		textChannel: message.channel.id,
		voiceChannel: voiceChannel.id,
	});

	player.connect();
} else {
	player = client.music.players.get(message.guild.id);
}

aparently the client.music.create deleted the existing player for that guild and made a new one.

Since I already am here, is there something similar to the Utils.formatTime in the rewrite like there was in the previous version?

from erela.js.

karelkryda avatar karelkryda commented on July 20, 2024

Oh, I haven't noticed you're not checking to see if it's already connected

EDIT: I'm using own timeFormat method

EDIT#2: From doc https://www.npmjs.com/package/humanize-duration

from erela.js.

Solaris9 avatar Solaris9 commented on July 20, 2024

The socketClosed event is emitted whenever Lavalinks connection to the voice channel is closed, that can be for a number of reasons, Erela will try to reconnect if it's not a bad resson.

You can check what code it is for the second argument against these https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-close-event-codes.

aparently the client.music.create deleted the existing player for that guild and made a new one.

Manager#create returns the player if it already exists.

Since I already am here, is there something similar to the Utils.formatTime in the rewrite like there was in the previous version?

No, it was removed, you can check the updating guides for what was changed between the v1 and v2.

from erela.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.