Cryingfreeman74
Cryingfreeman74
DIAdiscord.js - Imagine an app
Created by Cryingfreeman74 on 1/5/2024 in #djs-questions
How to use a custom font in canvas
code:
registerFont('Montserrat-Black.ttf', { family: 'Montserrat Black' });
//...
ctx.fillStyle = 'white';
ctx.font = '35px Montserrat Black';
ctx.fillText(message, 280, 114, 710);
registerFont('Montserrat-Black.ttf', { family: 'Montserrat Black' });
//...
ctx.fillStyle = 'white';
ctx.font = '35px Montserrat Black';
ctx.fillText(message, 280, 114, 710);
the Montserrat-Black.ttf file is in the same directory as the project and is not corrputed or anything, I've tried several times but I can't manage to use the font I want.
4 replies
DIAdiscord.js - Imagine an app
Created by Cryingfreeman74 on 12/25/2023 in #djs-voice
How to get access to player from different file
So I'm making a music bot and I wanted to have a slash command that makes the bot skip to the next song, but I'm having problems with getting access to the player object created in another file, what can I do? My two slash commands where one is the function that searches for a song and then plays it and the other one is to skip are in the same directory and I tried foing this:
//main command (search.js)
const player = createAudioPlayer();
module.exports = { player };
//main command (search.js)
const player = createAudioPlayer();
module.exports = { player };
//skip command (skip.js)
const { player } = require(playerPath) //playerPath is search.js
//skip command (skip.js)
const { player } = require(playerPath) //playerPath is search.js
By doing this if I try to log the player in skip.js this will print undefined.
3 replies
DIAdiscord.js - Imagine an app
Created by Cryingfreeman74 on 12/25/2023 in #djs-voice
How to remove event listener from player
code:
async function reproduceSong(interaction, connection, player, channel) {
if (sp > 0) {
try {
await search(queue[0]);
} catch (error) {
//song not found
channel.send("Song " + queue[0] + " not found, skipping.")
removeTopSong();
reproduceSong(interaction, connection, player, channel)
}

const resource = createAudioResource('Path');

player.play(resource);
channel.send("Now playing " + videoLink);

player.addListener("stateChange", (oldOne, newOne) => {
if (newOne.status == "idle") {
console.log("Song finished, moving to next.");
removeTopSong();
reproduceSong(interaction, connection, player, channel);
}
});

} else { //queue ended
interaction.editReply("Queue has ended.");
connection.destroy();
return -1;
}
}
async function reproduceSong(interaction, connection, player, channel) {
if (sp > 0) {
try {
await search(queue[0]);
} catch (error) {
//song not found
channel.send("Song " + queue[0] + " not found, skipping.")
removeTopSong();
reproduceSong(interaction, connection, player, channel)
}

const resource = createAudioResource('Path');

player.play(resource);
channel.send("Now playing " + videoLink);

player.addListener("stateChange", (oldOne, newOne) => {
if (newOne.status == "idle") {
console.log("Song finished, moving to next.");
removeTopSong();
reproduceSong(interaction, connection, player, channel);
}
});

} else { //queue ended
interaction.editReply("Queue has ended.");
connection.destroy();
return -1;
}
}
So I have this recursive function that uses a queue to play songs, but I noticed that when I add a second song to the queue and it switches to that song, the old listener is still active and makes it skip a song since it removes the top song in the queue. Is there a way to eliminate that listener before recalling the function?
3 replies
DIAdiscord.js - Imagine an app
Created by Cryingfreeman74 on 12/8/2023 in #djs-voice
Bot doesn't stop playing if I try to change what it's playing
I use a slash command to obtain a keyword to search on youtube and it works, but if I try to use the command a second time it downloads the new audio but does not change to playing it immediatly, instead it continues playing the old track for around 10-20 seconds and then starts playing the new song. Code:
try {
if (!interaction.options.getString("keyword")) interaction.reply("No prompt given");

await search(interaction.options.getString("keyword"));

//if already playing
if(activeSubscription){
subscription.unsubscribe();
player.stop();
console.log("subscription cancelled")
activeSubscription = false;
};


//getting guild, member and voice channel info
const guild = interaction.client.guilds.cache.get(interaction.guildId);
const member = guild.members.cache.get(interaction.member.user.id);
var voiceChannel = member.voice.channel;

interaction.reply('playing ' + videoLink);

const connection = joinVoiceChannel({ //joins the voice chat
channelId: voiceChannel.id,
guildId: guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});

//create audio player
const player = createAudioPlayer();

player.on(AudioPlayerStatus.Playing, () => {
console.log('The audio player has started playing!');
});

player.on('error', error => {
console.error(`Error: ${error.message} with resource`);
});

//create and play audio
const resource = createAudioResource('C:\\Users\\Marco\\Documents\\visual studio projects\\youtube_bot\\audio.mp3');

const subscription = connection.subscribe(player);
activeSubscription = true;

player.play(resource);

} catch (error) {
interaction.reply("Not found.")
}
try {
if (!interaction.options.getString("keyword")) interaction.reply("No prompt given");

await search(interaction.options.getString("keyword"));

//if already playing
if(activeSubscription){
subscription.unsubscribe();
player.stop();
console.log("subscription cancelled")
activeSubscription = false;
};


//getting guild, member and voice channel info
const guild = interaction.client.guilds.cache.get(interaction.guildId);
const member = guild.members.cache.get(interaction.member.user.id);
var voiceChannel = member.voice.channel;

interaction.reply('playing ' + videoLink);

const connection = joinVoiceChannel({ //joins the voice chat
channelId: voiceChannel.id,
guildId: guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});

//create audio player
const player = createAudioPlayer();

player.on(AudioPlayerStatus.Playing, () => {
console.log('The audio player has started playing!');
});

player.on('error', error => {
console.error(`Error: ${error.message} with resource`);
});

//create and play audio
const resource = createAudioResource('C:\\Users\\Marco\\Documents\\visual studio projects\\youtube_bot\\audio.mp3');

const subscription = connection.subscribe(player);
activeSubscription = true;

player.play(resource);

} catch (error) {
interaction.reply("Not found.")
}
5 replies