Adan_ea
Adan_ea
DIAdiscord.js - Imagine an app
Created by Adan_ea on 3/12/2024 in #djs-questions
Bulk delete stopping at 50
No description
5 replies
DIAdiscord.js - Imagine an app
Created by Adan_ea on 11/22/2023 in #djs-questions
voice.setRTCRegion(null) not working
HI, I have this code to change the region and it works perfectly except the null option
const buildSelectMenu = (regions: Collection<string, VoiceRegion>) => {
return new StringSelectMenuBuilder()
.setCustomId('voiceSetRTCRegionMenu')
.setPlaceholder('Change la région de ton serveur')
.addOptions([
{
label: 'Auto',
value: 'null',
emoji: '🌍'
},
...regions.map((region: VoiceRegion) => ({
label: region.name,
value: region.id,
emoji: '🌍'
}))
]);
};

export const buildVoiceSetRTCRegionActionRow = (regions: Collection<string, VoiceRegion>) => {
return new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(buildSelectMenu(regions));
};

export default {
data: {
name: `voiceSetRTCRegionMenu`
},
async execute(interaction: UserSelectMenuInteraction) {
await interaction.deferUpdate();
const region: string = interaction.values[0];
const member = interaction.member as GuildMember;
const voiceChannel = member.voice.channel;

if (voiceChannel) {
if (region === 'null') {
console.log("it's null already");
await voiceChannel.setRTCRegion(null, 'Auto');
} else await voiceChannel.setRTCRegion(region);
}

const newEmbed = new EmbedBuilder()
.setTitle('La région a bien été changée')
.setColor(Colors.random);

return interaction.update({
embeds: [newEmbed],
components: []
});
}
};
const buildSelectMenu = (regions: Collection<string, VoiceRegion>) => {
return new StringSelectMenuBuilder()
.setCustomId('voiceSetRTCRegionMenu')
.setPlaceholder('Change la région de ton serveur')
.addOptions([
{
label: 'Auto',
value: 'null',
emoji: '🌍'
},
...regions.map((region: VoiceRegion) => ({
label: region.name,
value: region.id,
emoji: '🌍'
}))
]);
};

export const buildVoiceSetRTCRegionActionRow = (regions: Collection<string, VoiceRegion>) => {
return new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(buildSelectMenu(regions));
};

export default {
data: {
name: `voiceSetRTCRegionMenu`
},
async execute(interaction: UserSelectMenuInteraction) {
await interaction.deferUpdate();
const region: string = interaction.values[0];
const member = interaction.member as GuildMember;
const voiceChannel = member.voice.channel;

if (voiceChannel) {
if (region === 'null') {
console.log("it's null already");
await voiceChannel.setRTCRegion(null, 'Auto');
} else await voiceChannel.setRTCRegion(region);
}

const newEmbed = new EmbedBuilder()
.setTitle('La région a bien été changée')
.setColor(Colors.random);

return interaction.update({
embeds: [newEmbed],
components: []
});
}
};
4 replies
DIAdiscord.js - Imagine an app
Created by Adan_ea on 9/19/2023 in #djs-questions
Unable to import a component from a file to another
Hi, i'm trying to get a select menu exported in a file in order to use it in another one by importing it but i get this error (i tried with buttons and i got the same thing): When the function is in the same file i don't get the issue
TypeError: (0 , modulesMenu_1.buildSelectMenu) is not a function
at Object.execute (\bot\dist\modules\setup\commands\module.js:52:68)
at handleCommandInteraction (\bot\dist\modules\core\events\client\interactionCreate.js:36:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (\bot\dist\modules\core\events\client\interactionCreate.js:17:13)
TypeError: (0 , modulesMenu_1.buildSelectMenu) is not a function
at Object.execute (\bot\dist\modules\setup\commands\module.js:52:68)
at handleCommandInteraction (\bot\dist\modules\core\events\client\interactionCreate.js:36:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (\bot\dist\modules\core\events\client\interactionCreate.js:17:13)
The func is :
export const buildSelectMenu = (guildSettings: IGuild) => {
const selectMenu = new StringSelectMenuBuilder()
.setCustomId("modulesMenu")
.setPlaceholder(value)
.addOptions(/*options*/);

const row = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu);
return row;
};
export const buildSelectMenu = (guildSettings: IGuild) => {
const selectMenu = new StringSelectMenuBuilder()
.setCustomId("modulesMenu")
.setPlaceholder(value)
.addOptions(/*options*/);

const row = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu);
return row;
};
and i call it like this with the good import:
const selectMenu = buildSelectMenu(guildSettings);
const selectMenu = buildSelectMenu(guildSettings);
When the function buildSelectMenu is in the same file, i dont get this error I'm using Typescript 5.1.6 and djs v14.11.0
10 replies
DIAdiscord.js - Imagine an app
Created by Adan_ea on 7/25/2023 in #djs-questions
Building slash commands differently
Hi, i had a discord bot on v13 and JS and i did this to implement slash commands
module.exports = {
name: 'updatepic',
description: '[ADMIN]',
permissions: [PermissionsBitField.Flags.Administrator], //i handle this in interactionCreate
category: 'database', //irrelevant, just for help command
usage: 'updatepic [link]', //irrelevant, just for help command
examples: ['updatepic default'], //irrelevant, just for help command
options: [
{
name: 'default',
description: 'Photo hors steram',
type: ApplicationCommandOptionType.String,
required: false
},
{
name: 'live',
description: "Photo lors d'un stream",
type: ApplicationCommandOptionType.String,
required: false
}
],
async runInteraction(client, interaction) {}
};
module.exports = {
name: 'updatepic',
description: '[ADMIN]',
permissions: [PermissionsBitField.Flags.Administrator], //i handle this in interactionCreate
category: 'database', //irrelevant, just for help command
usage: 'updatepic [link]', //irrelevant, just for help command
examples: ['updatepic default'], //irrelevant, just for help command
options: [
{
name: 'default',
description: 'Photo hors steram',
type: ApplicationCommandOptionType.String,
required: false
},
{
name: 'live',
description: "Photo lors d'un stream",
type: ApplicationCommandOptionType.String,
required: false
}
],
async runInteraction(client, interaction) {}
};
But i'm trying to do recreate this with TS and i don't seem to be able to do it this way, Also : How should i manage to get this architecture with sub commands ? I find this way easier to read so i'd like to keep it that way if possible
16 replies