Xalri
Xalri
DIAdiscord.js - Imagine an app
Created by Xalri on 7/16/2024 in #djs-questions
Interaction problem
Hello, a strange thing happend to me. I log interaction.channel in interactioncreate event and it's set, then i log it in my command, wich is executed few lines after the first log, and now it's not set anymore InteractionCreate event:
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if(!interaction.guild) return;
if(interaction.type === InteractionType.ApplicationCommand){

//some javascript code

console.log("INTERACTION CREATE : " + JSON.stringify(interaction.channel))
}
}
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if(!interaction.guild) return;
if(interaction.type === InteractionType.ApplicationCommand){

//some javascript code

console.log("INTERACTION CREATE : " + JSON.stringify(interaction.channel))
}
}
output:
INTERACTION CREATE : {"type":0,"guild":"1250125877203701841","guildId":"1250125877203701841","permissionOverwrites":["1250125877203701841","1260738028658364551","1260738028062638151","1260738030206189660"],"messages":[],"threads":[],"nsfw":false,"flags":0,"id":"1262593119648747642","name":"🛬・welcome","rawPosition":0,"parentId":"1262593112547659818","topic":null,"lastMessageId":null,"defaultThreadRateLimitPerUser":null,"rateLimitPerUser":0,"createdTimestamp":1721096057570}
INTERACTION CREATE : {"type":0,"guild":"1250125877203701841","guildId":"1250125877203701841","permissionOverwrites":["1250125877203701841","1260738028658364551","1260738028062638151","1260738030206189660"],"messages":[],"threads":[],"nsfw":false,"flags":0,"id":"1262593119648747642","name":"🛬・welcome","rawPosition":0,"parentId":"1262593112547659818","topic":null,"lastMessageId":null,"defaultThreadRateLimitPerUser":null,"rateLimitPerUser":0,"createdTimestamp":1721096057570}
auto.js:
module.exports = {

data: new SlashCommandBuilder()

.setName('auto')

.setDescription('automatically create channels'),

async execute(interaction) {


//some javascript code

console.log(JSON.stringify(interaction.channel))

}
}
module.exports = {

data: new SlashCommandBuilder()

.setName('auto')

.setDescription('automatically create channels'),

async execute(interaction) {


//some javascript code

console.log(JSON.stringify(interaction.channel))

}
}
output:
null
null
6 replies
DIAdiscord.js - Imagine an app
Created by Xalri on 7/13/2024 in #djs-questions
Problem with rest module
So i asked in #djs-help-v14 a few time about my deploy command not working, especially all lines after the rest.put. Since i put this code in my ready event, everyone and me thought that i was rate limit. But the night after someone said that to me, it worked again. then, i removed the code from my ready event, changed the way to execute it so i executed it only 1 time, continued to work on my bot, and when i added a new command and executed my deploy command, it didn't work. I thought it was rate limit again because the var "response = rest.put(..." was empty. But i just found about client.rest.on("response", console.log) and i saw that i was not rate limit. So i'm asking here for help deploy_command.js:
function deploy_commands(){


const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');


const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js') || file.endsWith('.mjs'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);




// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands. TEST`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
).then(async () => {
console.log(`THEN THEN THEN Successfully reloaded ${data.length} application (/) commands.`)
}).catch((err) => {
console.error(err)
});



console.log("TEST TEST TEST")

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
}




module.exports = deploy_commands
// deploy_commands()
function deploy_commands(){


const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');


const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js') || file.endsWith('.mjs'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);




// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands. TEST`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
).then(async () => {
console.log(`THEN THEN THEN Successfully reloaded ${data.length} application (/) commands.`)
}).catch((err) => {
console.error(err)
});



console.log("TEST TEST TEST")

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
}




module.exports = deploy_commands
// deploy_commands()
one of the 10 000000 rest reponse:
{
method: 'PUT',
path: '/channels/1260958647878422529/permissions/1260738030206189660',
route: '/channels/:id/permissions/:id',
options: {
body: '{"id":"1260738030206189660","type":0,"allow":"0","deny":"2048"}',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'DiscordBot (https://discord.js.org, 2.3.0) discord.js/14.15.3 Node.js/18.17.0',
Authorization: 'Bot xxxxxxxxxx'
},
method: 'PUT',
dispatcher: undefined
},
data: {
body: {
id: '1260738030206189660',
type: 0,
allow: [PermissionsBitField],
deny: [PermissionsBitField]
},
files: undefined,
auth: true,
signal: undefined
},
retries: 0
}
{
method: 'PUT',
path: '/channels/1260958647878422529/permissions/1260738030206189660',
route: '/channels/:id/permissions/:id',
options: {
body: '{"id":"1260738030206189660","type":0,"allow":"0","deny":"2048"}',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'DiscordBot (https://discord.js.org, 2.3.0) discord.js/14.15.3 Node.js/18.17.0',
Authorization: 'Bot xxxxxxxxxx'
},
method: 'PUT',
dispatcher: undefined
},
data: {
body: {
id: '1260738030206189660',
type: 0,
allow: [PermissionsBitField],
deny: [PermissionsBitField]
},
files: undefined,
auth: true,
signal: undefined
},
retries: 0
}
71 replies
DIAdiscord.js - Imagine an app
Created by Xalri on 7/4/2024 in #djs-voice
No sound ( no green circle)
Hello, i followed the official discord js v14 voice guide and my bot is not playing any sound. No green circle too. Here's the code:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus, NoSubscriberBehavior } = require('@discordjs/voice');
const fs = require('fs');
const { generateDependencyReport } = require('@discordjs/voice');

module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Play audio in your voice channel'),
async execute(interaction) {

const connection = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false
});

connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});


connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
]);
// Seems to be reconnecting to a new channel - ignore disconnect
} catch (error) {
// Seems to be a real disconnect which SHOULDN'T be recovered from
connection.destroy();
}
});


const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});

player.on('stateChange', (oldState, newState) => {
console.log(`Audio player transitioned from ${oldState.status} to ${newState.status}`);
});

const resource = createAudioResource('../../sound.mp3');

player.play(resource);

const subscription = connection.subscribe(player);

if (subscription) {

setTimeout(() => subscription.unsubscribe(), 5_000);
}

interaction.reply("Now playing")

},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus, NoSubscriberBehavior } = require('@discordjs/voice');
const fs = require('fs');
const { generateDependencyReport } = require('@discordjs/voice');

module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Play audio in your voice channel'),
async execute(interaction) {

const connection = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false
});

connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});


connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
]);
// Seems to be reconnecting to a new channel - ignore disconnect
} catch (error) {
// Seems to be a real disconnect which SHOULDN'T be recovered from
connection.destroy();
}
});


const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});

player.on('stateChange', (oldState, newState) => {
console.log(`Audio player transitioned from ${oldState.status} to ${newState.status}`);
});

const resource = createAudioResource('../../sound.mp3');

player.play(resource);

const subscription = connection.subscribe(player);

if (subscription) {

setTimeout(() => subscription.unsubscribe(), 5_000);
}

interaction.reply("Now playing")

},
};
Here's the generateDependencyReport:
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.17.0
- prism-media: 1.3.5
Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: not found
Encryption Libraries
- sodium-native: not found
- sodium: not found
- libsodium-wrappers: 0.7.13
- tweetnacl: not found
FFmpeg
- version: 6.0-static https://johnvansickle.com/ffmpeg/
- libopus: yes
--------------------------------------------------
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.17.0
- prism-media: 1.3.5
Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: not found
Encryption Libraries
- sodium-native: not found
- sodium: not found
- libsodium-wrappers: 0.7.13
- tweetnacl: not found
FFmpeg
- version: 6.0-static https://johnvansickle.com/ffmpeg/
- libopus: yes
--------------------------------------------------
115 replies
DIAdiscord.js - Imagine an app
Created by Xalri on 6/28/2024 in #djs-questions
Problem with variable through multiple file
So i have 4 commands wich are like that:
const { SlashCommandBuilder } = require('discord.js');
const { cchannel } = require('./commands_channel');
const { wchannel } = require('./welcome_channel');
const { gechannel } = require('./general_channel');


module.exports = {
data: new SlashCommandBuilder()
.setName('goodbye_channel')
.setDescription('setup the goodbye channel'),
async execute(interaction) {
// interaction.guild is the object representing the Guild in which the command was run
const goodbye_channel = interaction.channel.id;
module.exports.gochannel = goodbye_channel
await interaction.reply({ content: Channel saved as Goodbye channel., ephemeral: true});

console.log(Command Channel: ${cchannel === undefined? 'Not set' : cchannel});
console.log(Goodbye Channel: ${goodbye_channel === undefined? 'Not set' : goodbye_channel});
console.log(Welcome Channel: ${wchannel === undefined? 'Not set' : wchannel});
console.log(General Channel: ${gechannel === undefined? 'Not set' : gechannel});

if(gechannel !== undefined && cchannel !== undefined && wchannel !== undefined){
module.exports.isConfig = true;
}

},
};
const { SlashCommandBuilder } = require('discord.js');
const { cchannel } = require('./commands_channel');
const { wchannel } = require('./welcome_channel');
const { gechannel } = require('./general_channel');


module.exports = {
data: new SlashCommandBuilder()
.setName('goodbye_channel')
.setDescription('setup the goodbye channel'),
async execute(interaction) {
// interaction.guild is the object representing the Guild in which the command was run
const goodbye_channel = interaction.channel.id;
module.exports.gochannel = goodbye_channel
await interaction.reply({ content: Channel saved as Goodbye channel., ephemeral: true});

console.log(Command Channel: ${cchannel === undefined? 'Not set' : cchannel});
console.log(Goodbye Channel: ${goodbye_channel === undefined? 'Not set' : goodbye_channel});
console.log(Welcome Channel: ${wchannel === undefined? 'Not set' : wchannel});
console.log(General Channel: ${gechannel === undefined? 'Not set' : gechannel});

if(gechannel !== undefined && cchannel !== undefined && wchannel !== undefined){
module.exports.isConfig = true;
}

},
};
(the same for the other channel like general_channel alias gechannel, command_channel alias cchannel and welcome_channel alias wechannel) but every time, the log only show the channel of the command (the channel logged locally, not through imports) plls help me
3 replies
DIAdiscord.js - Imagine an app
Created by Xalri on 6/28/2024 in #djs-voice
No audio are played (no green circle)
No description
12 replies
DIAdiscord.js - Imagine an app
Created by Xalri on 6/23/2024 in #djs-questions
Problem while creating category
i have a problem while creating channel is specific category. Sometime one of the two category i'm creating (the first one, "travel_category") is not created so when i assign a channel in this category, i have an error. But sometime it works just fine, the cateogry is created and everything works. Here's the code:
const travel_category = await interaction.guild.channels.create({name: "traveler", type: ChannelType.GuildCategory });
const main_category = await interaction.guild.channels.create({name: "main", type: ChannelType.GuildCategory });


sleep(1000)


welcome_channel = await interaction.guild.channels.create({
name: arriving_emoji + "・Welcome",
type: ChannelType.GuildText, // syntax has changed a bit
permissionOverwrites: [{ // same as before
id: interaction.guild.id,
allow: [PermissionFlagsBits.ViewChannel],
deny: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.CreatePrivateThreads, PermissionFlagsBits.CreatePublicThreads]
}]
});
welcome_channel.setParent(travel_category.id)
const travel_category = await interaction.guild.channels.create({name: "traveler", type: ChannelType.GuildCategory });
const main_category = await interaction.guild.channels.create({name: "main", type: ChannelType.GuildCategory });


sleep(1000)


welcome_channel = await interaction.guild.channels.create({
name: arriving_emoji + "・Welcome",
type: ChannelType.GuildText, // syntax has changed a bit
permissionOverwrites: [{ // same as before
id: interaction.guild.id,
allow: [PermissionFlagsBits.ViewChannel],
deny: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.CreatePrivateThreads, PermissionFlagsBits.CreatePublicThreads]
}]
});
welcome_channel.setParent(travel_category.id)
thx
38 replies