Comments (13)
oh i accidentally was right :0
from erela.js.
Can you show me your code? @Knatschkopp
from erela.js.
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.
Any errors in console?
from erela.js.
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.
Try tu put some console.log() to code
from erela.js.
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.
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.
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.
Try to put console.log("SOMETHING")
into .on("socketClosed", player => {
from erela.js.
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.
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.
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)
- Feature Request: ytmsearch
- Weird Queue Problem HOT 4
- defaultSearchPlatform does not work HOT 3
- I donβt understand anything anymore
- Broken with nodejs 18.6 HOT 2
- updateVoiceState on the client issue HOT 2
- Error: Cannot read properties of undefined (reading 'track')
- Unexpected token in JSON at position 0 HOT 2
- Add queue/player events
- Cannot read properties of undefined (reading 'map') : Manager.js:155:36 HOT 1
- Update HOT 6
- Init bug HOT 8
- petitio causing a lot of errors HOT 25
- petitio: unexpected token in json HOT 4
- Plugin Issues HOT 1
- Unexpected token in JSON at position 0 HOT 3
- SyntaxError: Unexpected token in JSON at position 0 on Linux. HOT 1
- Some plugins does not work after latest update HOT 2
- Cannot read properties of undefined (reading 'map'): Manager.js:161:36
- TypeError: finalQuery.match is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from erela.js.