Apokalypt
Apokalypt
DIAdiscord.js - Imagine an app
Created by Apokalypt on 10/30/2024 in #djs-questions
"ApplicationCommandType.User" is not assignable to parameter of type "ContextMenuCommandType"
I'm using discord.js with Typescript and I encounter the error TS2345: Argument of type ApplicationCommandType.User is not assignable to parameter of type ContextMenuCommandType But if I look in the type definition I can see type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User; Code
const commandType = ApplicationCommandType.User;
return new ContextMenuCommandBuilder()
.setType(commandType);
const commandType = ApplicationCommandType.User;
return new ContextMenuCommandBuilder()
.setType(commandType);
Versions - Node :white_right_arrow: 20.16.0 - discordjs :white_right_arrow: 14.16.3 - discord-api-types :white_right_arrow: 0.37.103 (installed as dev dependencies) - Typescript :white_right_arrow: 5.6.3
4 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 8/6/2024 in #djs-questions
What is the best way to list the members inside a voice channel ?
Hello I would like to know the best way to list all members inside a voice channel. Does the property "members" is fully reliable ? Right now I have this code but I wanted to be sure that's the correct way
const channel = await guild.channels.fetch("<id>")
.catch( err => {
if (err.status === 404) {
return null;
}

throw err;
});
if (channel?.type !== ChannelType.GuildVoice) {
throw new Error("Not a voice channel");
return;
} else if (channel.members.size > 0) {
throw new Error("Some users are still in voice channel");
return;
}
const channel = await guild.channels.fetch("<id>")
.catch( err => {
if (err.status === 404) {
return null;
}

throw err;
});
if (channel?.type !== ChannelType.GuildVoice) {
throw new Error("Not a voice channel");
return;
} else if (channel.members.size > 0) {
throw new Error("Some users are still in voice channel");
return;
}
Versions - discord.js : 14.15.3 - node.js : 20.14.0
9 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 7/4/2024 in #djs-questions
My bot seems to not received the event "interactionCreate" from button sent in DM
Hello, My bot has sent a message to a user with a button but when the user click on the button the bot doesn't receive the interactionCreate event and an error is shown under the button on the user's app Code that send the message
await user.send({
embeds: [
{
description: `Vous venez d'être banni du serveur **${guild.name}**.\n\n`
+ `**Raison** : ${ctx.data.reason}\n`
+ `**Durée** : ${ctx.data.durationInSec > 0 ? formatDuration(ctx.data.durationInSec, "seconds") : "Infini"}`,
color: COLOR_RED
}
],
components: [{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
style: ButtonStyle.Primary,
label: "Contester / Demander un débanissement",
custom_id: "contest_sanction"
}
]
}]
})
await user.send({
embeds: [
{
description: `Vous venez d'être banni du serveur **${guild.name}**.\n\n`
+ `**Raison** : ${ctx.data.reason}\n`
+ `**Durée** : ${ctx.data.durationInSec > 0 ? formatDuration(ctx.data.durationInSec, "seconds") : "Infini"}`,
color: COLOR_RED
}
],
components: [{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
style: ButtonStyle.Primary,
label: "Contester / Demander un débanissement",
custom_id: "contest_sanction"
}
]
}]
})
The user correctly receives the message Handler event
// Code from guide
client.on(Events.InteractionCreate, readyClient => {
console.log("hey")
});
// Code from guide
client.on(Events.InteractionCreate, readyClient => {
console.log("hey")
});
- NodeJS :white_right_arrow: v20.14.0 - DiscordJS :white_right_arrow: 14.15.3
11 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 6/8/2024 in #djs-questions
How to determine the number of messages from a user ?
Hi, Is there a way to determine the number of messages sent by a user in a guild (the last message is too old to be in the bot cache) ? For now, I'm using my database to have this information but is there a way using Discord API to have this information ?
4 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 5/1/2024 in #djs-questions
Is there a way to get rate-limit data about an action (like update thread name) ?
I would like to check if my bot is rate-limited before trying to update the name of a thread. Is there a way to do that ?
12 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 4/1/2024 in #djs-questions
In autocomplete, how can I get the value of an option type "User" ?
No description
4 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 2/19/2024 in #djs-questions
Is it possible to receive ephemeral message in "messageCreate" event ?
Hello everyone, I'm going back on the code of an old project and I notice that in the handler for the "messageCreate" event there is a check on the "ephemeral" flag before performing an action. From what I understand about ephemeral messages, there's no reason to perform this check. However, I'd like to have some validation from you. Can ephemeral messages be received in this event? And if so, do we need to set up anything special to receive them? Versions - NodeJS: 18.17.1 - DiscordJS: 14.13.0
2 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 12/27/2023 in #djs-questions
Does <GuildMessageManager>.fetch({ limit: x }) return a sorted Collection of message ?
Hi When I call the method fetch from GuildMessageManager, I'd like to know if we can be sure that the collection returned is sorted and that the .last() method returns the real last message sent. In other words, does this code will always return the last message sent:
const channel: TextChannel = ....;
const messages = await channel.messages.fetch({ limit: 2 });
const lastMessage = messages.last(); // Are we sure that it's the real last message sent ??
const channel: TextChannel = ....;
const messages = await channel.messages.fetch({ limit: 2 });
const lastMessage = messages.last(); // Are we sure that it's the real last message sent ??
Versions - DiscordJs <:white_right_arrow:1182354037346148482> 14.14.1 - NodeJs <:white_right_arrow:1182354037346148482> 18.17.1
3 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 12/7/2023 in #djs-questions
How to differentiate an defer interaction
Hi I would like to know how I can differentiate the method used to defer the interaction since there is deferReply and deferUpdate. Is it even possible ? If yes, how because I only see one property deferred set to true by both of the method ? NodeJS : 18.x DiscordJS: 14.14.1
10 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 11/27/2023 in #djs-questions
How to properly check if the channel fetch is one where threads can be created?
Hi, I have the following code :
const supportChannelID = "an-id";
const channel = await guild.channels.fetch(supportChannelID);
const supportChannelID = "an-id";
const channel = await guild.channels.fetch(supportChannelID);
I would like to know the proper way to check that the channel supports thread creation in order to later write:
channel.threads.create({ ... })
channel.threads.create({ ... })
Because currently, using Typescript, with the code above it says that the property "threads" doesn't exist in StageChannel...
5 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 3/28/2023 in #djs-questions
Does a bot can fetch discord user connections ?
Hello, I wonder if it is possible for a bot to read the connections of users (PSN name, Spotify, ...). I'm asking this even though I suspect the answer will be given by the documentation and methods available... - Discord.JS : 14.8.0 - Node : 18.12.1
4 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 3/15/2023 in #djs-questions
My bot don't receive direct message
const { config } = require('dotenv');
config();

const { Client, GatewayIntentBits, ComponentType, ButtonStyle, Events } = require('discord.js');

const client = new Client({ intents: [GatewayIntentBits.DirectMessages] });

client.on(Events.ClientReady, () => {
console.log('[INFO] Bot is ready!');
});

client.on(Events.MessageCreate, async message => {
if (message.inGuild()) {
return;
}

console.log("Hello World");
});

client.login(process.env.MODMAIL_TOKEN);
const { config } = require('dotenv');
config();

const { Client, GatewayIntentBits, ComponentType, ButtonStyle, Events } = require('discord.js');

const client = new Client({ intents: [GatewayIntentBits.DirectMessages] });

client.on(Events.ClientReady, () => {
console.log('[INFO] Bot is ready!');
});

client.on(Events.MessageCreate, async message => {
if (message.inGuild()) {
return;
}

console.log("Hello World");
});

client.login(process.env.MODMAIL_TOKEN);
There is no log... I don't understand what I am missing...
5 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 3/14/2023 in #djs-questions
Does anyone know precisely how the cache works ?
I would like to know if there is a documentation about how the cache precisely works ? In fact, I'd like to know what items are cached and when, for example: are channels cached immediately? If so is it at the time of the "ready" event or another? What about the tags for the forum channels? Are threads cached at startup? My question is a bit vague but overall, I'd like to understand how caching works in detail so I'm interested in any documentation or info I know that I can have an answer by looking in the source code but if you have any information it could same me some time WumpsHeartyLove
7 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 2/26/2023 in #djs-questions
Is there a way to show modal on a ModalSubmitInteraction
I know that there is no function "showModal" on this type of interaction but I would like to know if there is a trick that would allow me to send a new modal on a ModalSubmitInteraction. Does anyone have an idea? - npm : 18.12.1 - discord.js : 15.7.1
4 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 1/29/2023 in #djs-questions
How to check if the user has the permission "manage posts"
Hi, I would like to know how I can check if a user has the "ManagePosts" permission? Indeed, this permission doesn't seem to exist in DiscordJS but that's what it's called on Discord Versions - Discord.JS arrow 14.7.1 - Node.JS arrow 18.12.1 Code
// message: Message<true>
// thread: AnyThreadChannel<true>

const userId = message.author.id;
// The permission ManagePosts doesn't exist...
if (!thread.permissionsFor(userId)?.has("ManagePosts")) {
return;
}
// message: Message<true>
// thread: AnyThreadChannel<true>

const userId = message.author.id;
// The permission ManagePosts doesn't exist...
if (!thread.permissionsFor(userId)?.has("ManagePosts")) {
return;
}
5 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 12/30/2022 in #djs-questions
How to know if a slash command is executed in a thread|post or in a channel ?
Hi, I don't understand how to check if the ChatInputInteraction was executed on a channel or a thread since there is no "threadId" property. Does anyone could help me please ?
7 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 12/21/2022 in #djs-questions
Is it possible to have an autocomplete user command ?
I saw in the documentation that a property of AutocompleteInteraction is "commandType". Does this mean that we can have a user/message command with autocomplete? If so, do you have an example of how this works? https://discord.js.org/#/docs/discord.js/main/class/AutocompleteInteraction?scrollTo=commandType
4 replies
DIAdiscord.js - Imagine an app
Created by Apokalypt on 11/13/2022 in #djs-questions
How can I use image from my assets folder in embed ?
Hi, I would like to create an embed and set the image from my assets folder. I already tried that (with no hopes 😂) :
new EmbedBuilder()
.setTitle('Need help')
.setImage('../assets/my_image.jpg')
new EmbedBuilder()
.setTitle('Need help')
.setImage('../assets/my_image.jpg')
But I receive an error - Discord.js : 14.6.0 - Node : 16.17.0
12 replies