2Flow2
2Flow2
DIAdiscord.js - Imagine an app
Created by 2Flow2 on 11/16/2023 in #djs-questions
awaitMessages does not reject on timeout?
I've got the following simple code collecting a single message from a user:
const checkUserFilter = i => i.user.id === interaction.user.id;
lastInteraction.update({ 'Please enter your message below:', components: [] });
await lastInteraction.channel.awaitMessages({ checkUserFilter, time: 3000, max: 1 })
.then(receivedMessages => { console.log("We successfully made it into the then!"); })
.catch(error => {
console.log("We got to the error!");
lastInteraction.editReply({ content: 'You took too long to respond, please run the command again to provide a new message.', components: [] });
});
const checkUserFilter = i => i.user.id === interaction.user.id;
lastInteraction.update({ 'Please enter your message below:', components: [] });
await lastInteraction.channel.awaitMessages({ checkUserFilter, time: 3000, max: 1 })
.then(receivedMessages => { console.log("We successfully made it into the then!"); })
.catch(error => {
console.log("We got to the error!");
lastInteraction.editReply({ content: 'You took too long to respond, please run the command again to provide a new message.', components: [] });
});
Output upon waiting 3000 milliseconds:
We successfully made it into the then!
We successfully made it into the then!
Why is it that when the awaitMessages() times out, the then statement is still running? Shouldn't it reject and go to the .catch block?
14 replies
DIAdiscord.js - Imagine an app
Created by 2Flow2 on 11/4/2023 in #djs-questions
How to validate if text is emoji? 🤔
My research has not turned up anything. I want users to be able to type in any emoji that is a valid emoji that could be used as a reaction via Discord's emoji picker. (I'm having the bot add reactions to a message.) I want to validate the character that the user enters is a valid emoji from the Discord emoji picker. (Standard, or custom server emoji. Whatever.) How do I go about validating this? Some regex rule? Some built-in method?
46 replies
DIAdiscord.js - Imagine an app
Created by 2Flow2 on 11/3/2023 in #djs-questions
Editing a message to insert a new component gives "Interaction failed" message?
Pretty simple thing here. Within my Discord bot, after a user successfully selects an option from a StringSelectMenu that the bot sends to them, in the code I have the bot .edit() the message that contained the StringSelectMenu in it that the user just chose from.
const firstMessage = await interaction.reply({content:'Blah blah blah choose an option', components:[actionRow]});
const checkUserFilter = i => i.user.id === interaction.user.id;
const choiceSelected = await firstMessage.awaitMessageComponent({ filter: checkUserFilter, time: 60000 });

if (choiceSelected.values[0] == "someOption") {
const channelSelect = new ChannelSelectMenuBuilder({ custom_id: 'channelSelect', placeholder: 'Select a channel'});
const channelSelectActionRow = new ActionRowBuilder().addComponents(channelSelect);

const chooseChannelMsg = await firstMessage.edit({ content: 'Now I am asking you to choose a channel!', components:[channelSelectActionRow]});
const firstMessage = await interaction.reply({content:'Blah blah blah choose an option', components:[actionRow]});
const checkUserFilter = i => i.user.id === interaction.user.id;
const choiceSelected = await firstMessage.awaitMessageComponent({ filter: checkUserFilter, time: 60000 });

if (choiceSelected.values[0] == "someOption") {
const channelSelect = new ChannelSelectMenuBuilder({ custom_id: 'channelSelect', placeholder: 'Select a channel'});
const channelSelectActionRow = new ActionRowBuilder().addComponents(channelSelect);

const chooseChannelMsg = await firstMessage.edit({ content: 'Now I am asking you to choose a channel!', components:[channelSelectActionRow]});
Everything runs fine, and the bot correctly edits the firstMessage message and moves on. (It edits firstMessage by providing new text and new, separate ChannelSelectMenu.) But even though everything was correct and the message gets edited, the user still sees the warning "Interaction failed" in the Discord UI. I have no idea why this warning is being thrown, as everything is running successfully and there are not crashes? How do I ensure "Interaction failed" is not displayed to the user after they select an option from the initial StringSelectMenu (in firstMessage)?
19 replies
DIAdiscord.js - Imagine an app
Created by 2Flow2 on 11/1/2023 in #djs-questions
Components falsely listed as optional?
In the documentation for ChannelSelectMenuBuilder, it says any parameters passed to the constructor method are optional. However, when I try to create a ChannelSelectMenuBuilder without any parameters at all (e.g. like const channelSelect = new ChannelSelectMenuBuilder({}); ) then Discord.js throws the error
ValidationError > s.string
Expected a string primitive

Received:
| undefined

at _StringValidator.handle
etc...
ValidationError > s.string
Expected a string primitive

Received:
| undefined

at _StringValidator.handle
etc...
(Passing the custom_id property in the parameter immediately fixes this.) So it doesn't seem like these parameters are completely optional if you can't construct a ChannelSelectMenuBuilder without any of them?
33 replies
DIAdiscord.js - Imagine an app
Created by 2Flow2 on 10/31/2023 in #djs-questions
Documentation error
Repeating what was said here: https://discord.com/channels/222078108977594368/222197033908436994/1166414494931628083 I'm trying to find all of the methods that StringSelectMenuBuilder inherits, but the link to BuildersSelectMenu on the page is broken. Does anyone know where that link is supposed to go, and also how the GitHub documentation can be updated to correct this?
3 replies
DIAdiscord.js - Imagine an app
Created by 2Flow2 on 9/15/2022 in #djs-questions
Roles and users missing from Integration permissions?
I can't tell if I am going crazy or if this is just weird behaviour from Discord. I have 25 roles in my Discord server. I have a bot which has slash commands which I would like to only be accessible to certain roles. However, when I click the "Add roles or members" button in the Integration settings page of the bot, it displays only SOME of the roles on the server, but not all of them. (i.e. an incomplete list) When I search for those roles via the search bar up top, they do not appear, either. Why are those roles not appearing on the settings page and how do I restrict slash command usage to those non-appearing roles?
23 replies