probablyraging
probablyraging
DIAdiscord.js - Imagine an app
Created by probablyraging on 3/4/2024 in #djs-questions
MaxListenersExceededWarning: Possible EventEmitter memory leak..
I recently switched my project from CJS to ESM, and while nothing in my code actually changed other than my import/export syntax, I am now getting the following alert which never happened in the years of running the bot before the changes
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 undefined listeners added to [Client]. Use emitter.setMaxListeners() to increase limit
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 undefined listeners added to [Client]. Use emitter.setMaxListeners() to increase limit
I have added setMaxListeners(20) to suppress the alert in the mean time, which it has, but I'm curious to know where this has come from and if I need to look into it more? I do have about 16 client event listeners, and I only use the intents/partials that I require
12 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 11/1/2023 in #djs-questions
Fetching ForumChannel threads returns ThreadChannels from all ForumChannels
I am trying to fetch threads from a specific ForumChannel, however, the ThreadChannels that are returned are not from the specified ForumChannel, but rather from every ForumChannel on the server
const forumChannel = await guild.channels.fetch('978694637088804884');
const threadChannels = await forumChannel.threads.fetch();
const forumChannel = await guild.channels.fetch('978694637088804884');
const threadChannels = await forumChannel.threads.fetch();
Here is a snippet of what is returned by threadChannels. Notice that the parentId fields are incorrect
'1147006027728965642' => ThreadChannel {
type: 11,
guild: [Guild],
guildId: '820889004055855144',
messages: [MessageManager],
members: [ThreadMemberManager],
flags: [ChannelFlagsBitField],
id: '1147006027728965642',
name: 'is this thumbnail clickable?',
parentId: '978691673842389053',
locked: false,
invitable: null,
archived: false,
autoArchiveDuration: 60,
archiveTimestamp: 1693537947352,
_createdTimestamp: 1693537947352,
ownerId: '758965903379136532',
lastMessageId: '1159043175013433374',
lastPinTimestamp: null,
rateLimitPerUser: 0,
messageCount: 4,
memberCount: 3,
totalMessageSent: 6,
appliedTags: [Array]
},
'1168586450711883847' => ThreadChannel {
type: 11,
guild: [Guild],
guildId: '820889004055855144',
messages: [MessageManager],
members: [ThreadMemberManager],
flags: [ChannelFlagsBitField],
id: '1168586450711883847',
name: 'need help repairing mp4 files',
parentId: '978553334854205450',
locked: false,
invitable: null,
archived: false,
autoArchiveDuration: 60,
archiveTimestamp: 1698683121136,
_createdTimestamp: 1698683121136,
ownerId: '244641191549730816',
lastMessageId: '1168912591482015824',
lastPinTimestamp: null,
rateLimitPerUser: 0,
messageCount: 2,
memberCount: 2,
totalMessageSent: 2,
appliedTags: []
},
'1147006027728965642' => ThreadChannel {
type: 11,
guild: [Guild],
guildId: '820889004055855144',
messages: [MessageManager],
members: [ThreadMemberManager],
flags: [ChannelFlagsBitField],
id: '1147006027728965642',
name: 'is this thumbnail clickable?',
parentId: '978691673842389053',
locked: false,
invitable: null,
archived: false,
autoArchiveDuration: 60,
archiveTimestamp: 1693537947352,
_createdTimestamp: 1693537947352,
ownerId: '758965903379136532',
lastMessageId: '1159043175013433374',
lastPinTimestamp: null,
rateLimitPerUser: 0,
messageCount: 4,
memberCount: 3,
totalMessageSent: 6,
appliedTags: [Array]
},
'1168586450711883847' => ThreadChannel {
type: 11,
guild: [Guild],
guildId: '820889004055855144',
messages: [MessageManager],
members: [ThreadMemberManager],
flags: [ChannelFlagsBitField],
id: '1168586450711883847',
name: 'need help repairing mp4 files',
parentId: '978553334854205450',
locked: false,
invitable: null,
archived: false,
autoArchiveDuration: 60,
archiveTimestamp: 1698683121136,
_createdTimestamp: 1698683121136,
ownerId: '244641191549730816',
lastMessageId: '1168912591482015824',
lastPinTimestamp: null,
rateLimitPerUser: 0,
messageCount: 2,
memberCount: 2,
totalMessageSent: 2,
appliedTags: []
},
Is this a bug or am I not understanding the use of GuildForumThreadManager#fetch()?
8 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 1/12/2023 in #djs-questions
Banning a previous user by ID
Command
module.exports = {
name: `test`,
description: `dummy command`,
defaultMemberPermissions: ['Administrator'],
cooldown: 0,
type: ApplicationCommandType.ChatInput,
options: [{
name: `user_id`,
description: `The user you want to ban`,
type: ApplicationCommandOptionType.User,
required: true
}],
/**
* @param {CommandInteraction} interaction
*/
async execute(interaction, client) {
const { options, member, guild, channel, user } = interaction;

await interaction.deferReply({ ephemeral: true }).catch(err => console.error(`${path.basename(__filename)} There was a problem deferring an interaction: `, err));

// Resolve the user by ID
const targetToBan = options.get('user_id');

// Ban the resolved user
guild.bans.create(targetToBan)

interaction.deleteReply();
}
}
module.exports = {
name: `test`,
description: `dummy command`,
defaultMemberPermissions: ['Administrator'],
cooldown: 0,
type: ApplicationCommandType.ChatInput,
options: [{
name: `user_id`,
description: `The user you want to ban`,
type: ApplicationCommandOptionType.User,
required: true
}],
/**
* @param {CommandInteraction} interaction
*/
async execute(interaction, client) {
const { options, member, guild, channel, user } = interaction;

await interaction.deferReply({ ephemeral: true }).catch(err => console.error(`${path.basename(__filename)} There was a problem deferring an interaction: `, err));

// Resolve the user by ID
const targetToBan = options.get('user_id');

// Ban the resolved user
guild.bans.create(targetToBan)

interaction.deleteReply();
}
}
targetToBan seems to resolve a user object
{
name: 'user_id',
type: 6,
value: 'xxxxxxxxxxxxxxxx',
user: User {
id: 'xxxxxxxxxxxxxx',
bot: false,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'xxxxxxxxxxxx',
discriminator: '3947',
avatar: '8b404e300e2c3e1a3c65cd488cac3098',
banner: undefined,
accentColor: undefined
}
}
{
name: 'user_id',
type: 6,
value: 'xxxxxxxxxxxxxxxx',
user: User {
id: 'xxxxxxxxxxxxxx',
bot: false,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'xxxxxxxxxxxx',
discriminator: '3947',
avatar: '8b404e300e2c3e1a3c65cd488cac3098',
banner: undefined,
accentColor: undefined
}
}
Error
Error [BanResolveId]: Couldn't resolve the user id to ban.
at GuildBanManager.create (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\discord.js\src\managers\GuildBanManager.js:157:20)
at Object.execute (C:\Users\proba\OneDrive\Desktop\4DC\commands\slash_commands\administration\test.js:34:20)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'BanResolveId'
}
Error [BanResolveId]: Couldn't resolve the user id to ban.
at GuildBanManager.create (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\discord.js\src\managers\GuildBanManager.js:157:20)
at Object.execute (C:\Users\proba\OneDrive\Desktop\4DC\commands\slash_commands\administration\test.js:34:20)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'BanResolveId'
}
6 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 11/8/2022 in #djs-questions
Non-ephemeral reply into an ephemeral reply - vice versa
Is it possible to defer an interaction non-ephemerally and then later followup or edit it to be ephemeral, or vice versa?
4 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 10/23/2022 in #djs-questions
ThreadChannel.setName and .setLocked issue
Trying to set a thread's name and then lock it, but neither of these methods seem to work correctly. setName works sporadically while setLocked nothing at all Sample
if (channel.isThread()) {
(await channel.setName('something')).setLocked();
}
if (channel.isThread()) {
(await channel.setName('something')).setLocked();
}
Full command
module.exports = {
name: `thread`,
description: `Mark threads as solved or closed`,
cooldown: 0,
type: ApplicationCommandType.ChatInput,
options: [{
name: `option`,
description: `Chose to mark the thread as solved or closed`,
type: ApplicationCommandOptionType.String,
required: true,
choices: [{ name: 'Solved', value: 'solved' },
{ name: 'Closed', value: 'closed' }]
}],
async execute(interaction) {
const { options, channel } = interaction;
await interaction.deferReply({ ephemeral: true });
if (!channel.isThread()) {
return interaction.reply({
content: `This is not a thread channel`,
ephemeral: true
});
}
switch (options.getString('option')) {
case 'solved': {
(await channel.setName(`[SOLVED] ${channel.name}`)).setLocked();
interaction.editReply({
content: `Thread has been closed and marked as solved`,
ephemeral: true
});
break;
}
}
}
}
module.exports = {
name: `thread`,
description: `Mark threads as solved or closed`,
cooldown: 0,
type: ApplicationCommandType.ChatInput,
options: [{
name: `option`,
description: `Chose to mark the thread as solved or closed`,
type: ApplicationCommandOptionType.String,
required: true,
choices: [{ name: 'Solved', value: 'solved' },
{ name: 'Closed', value: 'closed' }]
}],
async execute(interaction) {
const { options, channel } = interaction;
await interaction.deferReply({ ephemeral: true });
if (!channel.isThread()) {
return interaction.reply({
content: `This is not a thread channel`,
ephemeral: true
});
}
switch (options.getString('option')) {
case 'solved': {
(await channel.setName(`[SOLVED] ${channel.name}`)).setLocked();
interaction.editReply({
content: `Thread has been closed and marked as solved`,
ephemeral: true
});
break;
}
}
}
}
5 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 8/7/2022 in #djs-questions
Undici UND_ERR_ABORTED when fetching channel messages
Simply trying to fetch the most recent message in a channel when the error occurs. Am noticing Discord is being a little slow at the moment with things like deleting message, loading channel etc.. but not sure if this could be related • [email protected] • v16.16.0
await message.channel.messages.fetch({ limit: 1 }).then(async fetched => {...
await message.channel.messages.fetch({ limit: 1 }).then(async fetched => {...
C:\Users\proba\OneDrive\Desktop\4DC\node_modules\undici\lib\client.js:1333
errorRequest(client, request, err || new RequestAbortedError())
^

RequestAbortedError [AbortError]: Request aborted
at RequestHandler.abort (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\undici\lib\client.js:1333:44)
at abort (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\undici\lib\api\abort-signal.js:8:10)
at AbortSignal.self.<computed> (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\undici\lib\api\abort-signal.js:29:5)
at AbortSignal.[nodejs.internal.kHybridDispatch] (node:internal/event_target:643:20)
at AbortSignal.dispatchEvent (node:internal/event_target:585:26)
at abortSignal (node:internal/abort_controller:284:10)
at AbortController.abort (node:internal/abort_controller:315:5)
at Timeout.<anonymous> (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\discord.js\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:156:49)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
code: 'UND_ERR_ABORTED'
}
C:\Users\proba\OneDrive\Desktop\4DC\node_modules\undici\lib\client.js:1333
errorRequest(client, request, err || new RequestAbortedError())
^

RequestAbortedError [AbortError]: Request aborted
at RequestHandler.abort (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\undici\lib\client.js:1333:44)
at abort (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\undici\lib\api\abort-signal.js:8:10)
at AbortSignal.self.<computed> (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\undici\lib\api\abort-signal.js:29:5)
at AbortSignal.[nodejs.internal.kHybridDispatch] (node:internal/event_target:643:20)
at AbortSignal.dispatchEvent (node:internal/event_target:585:26)
at abortSignal (node:internal/abort_controller:284:10)
at AbortController.abort (node:internal/abort_controller:315:5)
at Timeout.<anonymous> (C:\Users\proba\OneDrive\Desktop\4DC\node_modules\discord.js\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:156:49)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
code: 'UND_ERR_ABORTED'
}
2 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/22/2022 in #djs-questions
How long do global command stay active?
Is there an expiry on global command? Or is it the case of registering them and then leaving them be until they need updating or whatever?
4 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/21/2022 in #djs-questions
Adding a new field to an existing embed
I'm currently fetching the message containing the embed I was to edit and then getting the embed, but I can't figure out how to add a field to it without having to resend the entire embed?
const message = await channel.messages.fetch(id);
const originalEmbed = message.embeds[0];

originalEmbed.addFields({ name: 'test', value: 'test' })
const message = await channel.messages.fetch(id);
const originalEmbed = message.embeds[0];

originalEmbed.addFields({ name: 'test', value: 'test' })
11 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/18/2022 in #djs-questions
Webhook avatar missing
const avatarURL = client.user.avatarURL({ format: 'png', size: 256 });

channel.createWebhook({ name: client.user.username, avatar: `${avatarURL}` }).then(webhook => {
//
});
const avatarURL = client.user.avatarURL({ format: 'png', size: 256 });

channel.createWebhook({ name: client.user.username, avatar: `${avatarURL}` }).then(webhook => {
//
});
10 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/18/2022 in #djs-questions
EmbedBuilder random .setColor()
Is it still possible to set a random color with EmbedBuilder?
3 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/14/2022 in #djs-questions
Select menu option value of modal returns 'undefined'
Modal component
const modal = new Modal()
.setTitle('Warning')
.setCustomId('warn-modal')

const select = new MessageSelectMenu()
.setCustomId('reason-select')
.setPlaceholder('Select')
.addOptions([
{ label: 'Rule 1 - harmful post/username/profile etc..', value: '1' },
{ label: 'Rule 2 - spamming and flooding', value: '2' },
{ label: 'Rule 3 - self promotion and unsolicited DMs', value: '3' },
{ label: 'Rule 4 - advertising discord servers and paid services', value: '4' },
{ label: 'Rule 5 - sub4sub type behaviour', value: '5' },
{ label: 'Rule 6 - openly discussing moderator actions', value: '6' },
{ label: 'Rule 7 - messages not in English', value: '7' },
{ label: 'Custom', value: 'Custom' }
])

const row = new MessageActionRow().addComponents([select]);
modal.addComponents(row);
await interaction.showModal(modal);
const modal = new Modal()
.setTitle('Warning')
.setCustomId('warn-modal')

const select = new MessageSelectMenu()
.setCustomId('reason-select')
.setPlaceholder('Select')
.addOptions([
{ label: 'Rule 1 - harmful post/username/profile etc..', value: '1' },
{ label: 'Rule 2 - spamming and flooding', value: '2' },
{ label: 'Rule 3 - self promotion and unsolicited DMs', value: '3' },
{ label: 'Rule 4 - advertising discord servers and paid services', value: '4' },
{ label: 'Rule 5 - sub4sub type behaviour', value: '5' },
{ label: 'Rule 6 - openly discussing moderator actions', value: '6' },
{ label: 'Rule 7 - messages not in English', value: '7' },
{ label: 'Custom', value: 'Custom' }
])

const row = new MessageActionRow().addComponents([select]);
modal.addComponents(row);
await interaction.showModal(modal);
Interaction handling
console.log(interaction.fields.getField('reason-select'))
console.log(interaction.fields.getField('reason-select'))
Result
{ value: undefined, type: 'SELECT_MENU', customId: 'reason-select' }
{ value: undefined, type: 'SELECT_MENU', customId: 'reason-select' }
So why is value 'undefined'?
2 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/14/2022 in #djs-questions
Fetching a forums channel
How can I fetch a forum channel, similar to guild.channels.cache.get()? When I do this for a forum channel it returns undefined
4 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/12/2022 in #djs-questions
Fetching audit logs when there is an AutoMod blocked message event throws an error
Fetching audit logs that contain an AutoMod blocked message event throws an error. How can I fix this?
guild.fetchAuditLogs({
limit: 1,
})
guild.fetchAuditLogs({
limit: 1,
})
--------ERROR-------
C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\GuildAuditLogs.js:489
this.target = this.changes.reduce((o, c) => {
^
TypeError: Cannot read properties of null (reading 'reduce')
at new GuildAuditLogsEntry (C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\GuildAuditLogs.js:489:34)
at new GuildAuditLogs (C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\GuildAuditLogs.js:202:21)
at Function.build (C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\GuildAuditLogs.js:212:18)
at Guild.fetchAuditLogs (C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\Guild.js:796:27)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.execute (C:\Users\proba\OneDrive\Desktop\CreatorBot\events\guild\guildMemberUpdate.js:13:33)
--------ERROR-------
C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\GuildAuditLogs.js:489
this.target = this.changes.reduce((o, c) => {
^
TypeError: Cannot read properties of null (reading 'reduce')
at new GuildAuditLogsEntry (C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\GuildAuditLogs.js:489:34)
at new GuildAuditLogs (C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\GuildAuditLogs.js:202:21)
at Function.build (C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\GuildAuditLogs.js:212:18)
at Guild.fetchAuditLogs (C:\Users\proba\OneDrive\Desktop\CreatorBot\node_modules\discord.js\src\structures\Guild.js:796:27)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.execute (C:\Users\proba\OneDrive\Desktop\CreatorBot\events\guild\guildMemberUpdate.js:13:33)
8 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/12/2022 in #djs-questions
AutoMod event when a message is flagged
Is there an event that fires when AutoMod flags a message? I want to build upon what AutoMod already offers for flagged messages (blocking and timeout), such as banning, sending a DM etc..
6 replies
DIAdiscord.js - Imagine an app
Created by probablyraging on 7/11/2022 in #djs-questions
Sending a DM to a user who the bot does not share a server with
I'd like to make a ban appeal process for my server/bot. When a user is banned using either the context menu or the systems /ban command, the guildBanAdd event is fired, I would then like to send the user a DM notifying them that they were banned and how to appeal it. However, seeing as once the guildBanAdd event is fired, that user is no longer in the server at that point, so I don't think it's possible for the bot to send them a DM, correct? Or am I missing something?
11 replies