Batimius
Batimius
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Batimius on 9/19/2023 in #djs-questions
Slash Command Guild Permission Overwrite
Hello there. I'll make this quick. In sort, I am making a command that applies slash command permission overwrites to servers based on a file it reads. Now, I did manage to write everything that sets up the properties object to be applied to the guild.commands.permissions.set() function, but for some reason, it just does not accept it. Here is an overview of the important chunks of code:
const guildPermissions: {id: string, permissions: ApplicationCommandPermissions[]}[] = []

{ // This is a loop
const permissions: ApplicationCommandPermissions[] = []

{ // This is also a loop
permissions.push({
id: roleId,
type: ApplicationCommandPermissionType.Role,
permission: true
})
}

guildPermissions.push({
id: commandId,
permissions,
})
}

guild.commands.permissions.set({
token: process.env.DISCORD_TOKEN,
permissions: guildPermissions // The "permissions" key is highlighted red with an error
})
const guildPermissions: {id: string, permissions: ApplicationCommandPermissions[]}[] = []

{ // This is a loop
const permissions: ApplicationCommandPermissions[] = []

{ // This is also a loop
permissions.push({
id: roleId,
type: ApplicationCommandPermissionType.Role,
permission: true
})
}

guildPermissions.push({
id: commandId,
permissions,
})
}

guild.commands.permissions.set({
token: process.env.DISCORD_TOKEN,
permissions: guildPermissions // The "permissions" key is highlighted red with an error
})
The error I get is the following:
Type '{ id: string; permissions: ApplicationCommandPermissions[]; }[]' is not assignable to type 'readonly ApplicationCommandPermissions[]'.
Type '{ id: string; permissions: ApplicationCommandPermissions[]; }' is missing the following properties from type 'ApplicationCommandPermissions': type, permissionts(2322)
index.d.ts(4620, 3): The expected type comes from property 'permissions' which is declared here on type '{ command: ApplicationCommandResolvable; } & EditApplicationCommandPermissionsMixin'
Type '{ id: string; permissions: ApplicationCommandPermissions[]; }[]' is not assignable to type 'readonly ApplicationCommandPermissions[]'.
Type '{ id: string; permissions: ApplicationCommandPermissions[]; }' is missing the following properties from type 'ApplicationCommandPermissions': type, permissionts(2322)
index.d.ts(4620, 3): The expected type comes from property 'permissions' which is declared here on type '{ command: ApplicationCommandResolvable; } & EditApplicationCommandPermissionsMixin'
I am unsure whether I am doing something wrong or this is a TS issue. If anyone knows how I could solve this, then it would be very helpful. Thank you for your time and help, I truly appreciate it.
5 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 8/5/2023 in #djs-voice
Is it possible to fetch a subscribed AudioPlayer from a VoiceConnection?
Hello there. So I'm making a song bot that plays local files. The current play command simply joins a voice channel (or moves to the current channel) and plays the song that was requested (from a selection of MP3 files on my local system). I am planning on making a queue system so you can queue whatever song you want. My problem comes with fetching the AudioPlayer. The discord.js/voice guide advised against keeping track of connections as you can accidentally create memory leaks. That said, I decided that I won't be keeping track of anything (apart from what is in the queue). From my understanding, an AudioPlayer is something like Media Player on Windows, an instance which a bunch of AudioResources can be passed in and it plays the latest one. If that is correct, then that means that it would be odd and wasteful to create an AudioPlayer for every single AudioResource, it would be the equivalent of opening a new Media Player window for every song. That being said, I plan on utilizing a single AudioPlayer per server. Now, since it was advised against to keep track of connections and such, is there a way for me to fetch that AudioPlayer using a VoiceConnection, or would I need to manually keep track of it? Also, would it maybe be better to create a new AudioPlayer for each song and just find a way to unsubscribe from the previous one? What do you recommend I do?
5 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 8/1/2023 in #djs-questions
TypeScript .getSubcommand() issue
5 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 1/5/2023 in #djs-questions
What is the difference between guildMemberAdd and guildMemberAvailable?
Just like the title says, what is the difference between guildMemberAdd and guildMemberAvailable? I know guildMemberAdd is when a user is added to the guild, but I have no idea what guildMemberAvailable is. I assume that it is when the user has agreed to the rules and maybe finished the cooldown (so when Discord holding them back is over), but I can't find it documented anywhere. If it is like I assumed it is, then can I use it reliably as a replacement for guildMemberAdd? What happens if you use it in a server that has no requirements? Would it be better to use it instead of guildMemberAdd? If someone could answer these questions, that would be amazing. Thank you for your time and help, it is truly appreciated.
4 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 1/3/2023 in #djs-questions
How would I convert a URL into an attachment?
Hello there. So, I'll keep this short. I have a messageDelete event handler, and I have a problem. When a user sends a sticker and deletes it, obviously, I cannot reuse that sticker in my log message. That said, I thought that I could probably retrieve the sticker URL and use it as a file attachment instead. The main problem is that I have no idea how to do that. If someone could enlighten me on how I could achieve this, that would be amazing. Thank you for your help, it is truly appreciated.
6 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 1/3/2023 in #djs-questions
Attaching already existing attachments to message
Hello there. So, as the title suggests, I want to attach already-existing message attachments on a new message. I am making a messageDelete event handler and I want to attach any files that have been deleted to the log message. Here is the code that I have so far:
Cog.add = new Event("messageDelete", async (message) => {
if (!logChannel) {logChannel = await message.client.channels.fetch(logChannelId)}
if (message.author.bot) {return}

const embed = new EmbedBuilder()
.setAuthor({name: message.author.tag, iconURL: await message.author.displayAvatarURL()})
.setTitle("Message Deleted")
.setDescription(`**Message sent by ${message.author} deleted in ${message.channel}**${(message.content) ? ":\n" + message.content : "."}`)
.setColor("#ca1919")
.setTimestamp()

await logChannel.send({embeds: [embed, ...message.embeds], files: [...message.attachments], stickers: [...message.stickers]})
})
Cog.add = new Event("messageDelete", async (message) => {
if (!logChannel) {logChannel = await message.client.channels.fetch(logChannelId)}
if (message.author.bot) {return}

const embed = new EmbedBuilder()
.setAuthor({name: message.author.tag, iconURL: await message.author.displayAvatarURL()})
.setTitle("Message Deleted")
.setDescription(`**Message sent by ${message.author} deleted in ${message.channel}**${(message.content) ? ":\n" + message.content : "."}`)
.setColor("#ca1919")
.setTimestamp()

await logChannel.send({embeds: [embed, ...message.embeds], files: [...message.attachments], stickers: [...message.stickers]})
})
Now, when I delete a message with an image attached, I get the following error:
TypeError: Cannot read properties of undefined (reading 'path')
at findName (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\MessagePayload.js:244:17)
at MessagePayload.resolveFile (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\MessagePayload.js:258:31)
at C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\MessagePayload.js:225:85
at Array.map (<anonymous>)
at MessagePayload.resolveFiles (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\MessagePayload.js:225:56)
at TextChannel.send (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:50)
at Client.<anonymous> (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\Cogs\Misc\generalLogs.js:32:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
TypeError: Cannot read properties of undefined (reading 'path')
at findName (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\MessagePayload.js:244:17)
at MessagePayload.resolveFile (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\MessagePayload.js:258:31)
at C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\MessagePayload.js:225:85
at Array.map (<anonymous>)
at MessagePayload.resolveFiles (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\MessagePayload.js:225:56)
at TextChannel.send (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:50)
at Client.<anonymous> (C:\Users\Batman212369\Desktop\Discord Bots\RHS-Bot V2\Cogs\Misc\generalLogs.js:32:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I really don't understand why this is a problem. I did think that it might be because I am not using an AttachmentBuilder, but the wiki clearly states that Array <Attachment> is also a viable option for the files argument. If someone could help me, that would be awesome. Thank you for your time and help, it is truly appreciated.
10 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 1/2/2023 in #djs-questions
Best way to find and delete user messages
Hello there. So, as the title implies, I want to know what the best way to fetch ALL user messages and then delete them. My idea on how to go about this is to utilize the MessageManager.fetch({}) command to get all messages, filter them using messages.filter(m => m.author.id === USER_ID), and then using the TextChannel.bulkDelete() function and passing all the messages as an array. Before putting this into practice though, I do have some questions. First and foremost is if this method is the most efficient. I don't want to waste resources and API calls when I don't need to, so is there a better way of going about this, or is this ultimately the best way? Also, will this method guarantee that I'll fetch ALL user messages, regardless of time passed, or will the filter only get the most recent ones? The command is responsible for deleting ALL user messages (well, I'll modify it to delete a specific number of messages in the future), so getting every message the user has sent (even if the first message was 2 years ago) is essential. That is all. If someone could help me with my issue, that would be amazing. Thank you for your time and help, it is truly appreciated.
16 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 11/12/2022 in #djs-questions
Problem with intents
Hello there. So, I just downloaded the new version of Discord.js, and I am surprised at how quickly I came across some errors. The first problem I came across was Intents.FLAGS being replaced. No problem there though, I quickly fixed that by replacing Intents.FLAGS with GatewayIntentBits. What is my problem? After doing that, it ended up giving me a RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined. error. Here are my intents:
const client = new DiscordJS.Client({
intents: [
GatewayIntentBits.GUILDS,
GatewayIntentBits.GUILD_MESSAGES,
GatewayIntentBits.GUILD_MEMBERS,
GatewayIntentBits.GUILD_BANS,
GatewayIntentBits.GUILD_EMOJIS_AND_STICKERS,
GatewayIntentBits.GUILD_INTEGRATIONS,
GatewayIntentBits.GUILD_WEBHOOKS,
GatewayIntentBits.GUILD_INVITES,
GatewayIntentBits.GUILD_VOICE_STATES,
GatewayIntentBits.GUILD_PRESENCES,
GatewayIntentBits.GUILD_MESSAGES,
GatewayIntentBits.GUILD_MESSAGE_REACTIONS,
GatewayIntentBits.GUILD_MESSAGE_TYPING,
GatewayIntentBits.DIRECT_MESSAGES,
GatewayIntentBits.DIRECT_MESSAGE_REACTIONS,
GatewayIntentBits.DIRECT_MESSAGE_TYPING,
GatewayIntentBits.GUILD_SCHEDULED_EVENTS
],
partials: [
"GUILD_MEMBER",
"MESSAGE",
"CHANNEL",
"GUILD_SCHEDULED_EVENT",
"REACTION",
"USER"
]
})
const client = new DiscordJS.Client({
intents: [
GatewayIntentBits.GUILDS,
GatewayIntentBits.GUILD_MESSAGES,
GatewayIntentBits.GUILD_MEMBERS,
GatewayIntentBits.GUILD_BANS,
GatewayIntentBits.GUILD_EMOJIS_AND_STICKERS,
GatewayIntentBits.GUILD_INTEGRATIONS,
GatewayIntentBits.GUILD_WEBHOOKS,
GatewayIntentBits.GUILD_INVITES,
GatewayIntentBits.GUILD_VOICE_STATES,
GatewayIntentBits.GUILD_PRESENCES,
GatewayIntentBits.GUILD_MESSAGES,
GatewayIntentBits.GUILD_MESSAGE_REACTIONS,
GatewayIntentBits.GUILD_MESSAGE_TYPING,
GatewayIntentBits.DIRECT_MESSAGES,
GatewayIntentBits.DIRECT_MESSAGE_REACTIONS,
GatewayIntentBits.DIRECT_MESSAGE_TYPING,
GatewayIntentBits.GUILD_SCHEDULED_EVENTS
],
partials: [
"GUILD_MEMBER",
"MESSAGE",
"CHANNEL",
"GUILD_SCHEDULED_EVENT",
"REACTION",
"USER"
]
})
If someone could help me, that would be awesome. Thank you for your time and help, it is truly appreciated. Full error stack:
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.
at Function.resolve (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\BitField.js:168:11)
at C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\BitField.js:163:54
at Array.map (<anonymous>)
at Function.resolve (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\BitField.js:163:40)
at new BitField (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\BitField.js:33:38)
at new IntentsBitField (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\IntentsBitField.js:9:1)
at Client._validateOptions (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\client\Client.js:482:25)
at new Client (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\client\Client.js:78:10)
at Object.<anonymous> (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\bot.js:24:16)
at Module._compile (node:internal/modules/cjs/loader:1105:14) {
code: 'BitFieldInvalid'
}
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.
at Function.resolve (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\BitField.js:168:11)
at C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\BitField.js:163:54
at Array.map (<anonymous>)
at Function.resolve (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\BitField.js:163:40)
at new BitField (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\BitField.js:33:38)
at new IntentsBitField (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\util\IntentsBitField.js:9:1)
at Client._validateOptions (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\client\Client.js:482:25)
at new Client (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\node_modules\discord.js\src\client\Client.js:78:10)
at Object.<anonymous> (C:\Users\Batman212369\Desktop\Discord Bots\Pin-Bot\bot.js:24:16)
at Module._compile (node:internal/modules/cjs/loader:1105:14) {
code: 'BitFieldInvalid'
}
Discord.js Version: 14.6.0 Node Version: 8.1.4
6 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 6/23/2022 in #djs-questions
How would I listen to DM messages?
Hello there. The title explains the question. How would I listen to any DM messages. client.on("messageCreate") does not seem to listen to any DM messages at all, so how would I be able to listen to DM messages in order to run commands there too? Thanks.
4 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 6/21/2022 in #djs-questions
'TypeError this.options.components?.map is not a function' when using spliceComponents() function
Hello there. I am fairly certain this is a bug rather than a question. I tried using the spliceComponents() function and got this error in return:
TypeError: this.options.components?.map is not a function
at MessagePayload.resolveData (C:\Users\Batman212369\Desktop\Discord Bots\MyBot\node_modules\discord.js\src\structures\MessagePayload.js:141:49)
at MessageManager.edit (C:\Users\Batman212369\Desktop\Discord Bots\MyBot\node_modules\discord.js\src\managers\MessageManager.js:130:8)
at Message.edit (C:\Users\Batman212369\Desktop\Discord Bots\MyBot\node_modules\discord.js\src\structures\Message.js:702:34)
at Interaction.callback (C:\Users\Batman212369\Desktop\Discord Bots\MyBot\Cogs\ticket.js:240:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
TypeError: this.options.components?.map is not a function
at MessagePayload.resolveData (C:\Users\Batman212369\Desktop\Discord Bots\MyBot\node_modules\discord.js\src\structures\MessagePayload.js:141:49)
at MessageManager.edit (C:\Users\Batman212369\Desktop\Discord Bots\MyBot\node_modules\discord.js\src\managers\MessageManager.js:130:8)
at Message.edit (C:\Users\Batman212369\Desktop\Discord Bots\MyBot\node_modules\discord.js\src\structures\Message.js:702:34)
at Interaction.callback (C:\Users\Batman212369\Desktop\Discord Bots\MyBot\Cogs\ticket.js:240:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Here is the code that generated this error:
Cog.add = new Interaction("claimTicket", async (interaction) => {
let ticket = await fetchTicketInfo({channelId: interaction.channelId})
if (ticket.claimantId) {
await interaction.reply({content: `This channel has already been claimed by <@${ticket.claimantId}>.`, ephemeral: true})
return
}

ticket.claimantId = interaction.user.id
await updateTicketInfo(ticket)

const unclaimButton = new MessageButton()
.setCustomId('unclaimTicket')
.setLabel('📝 Unclaim')
.setStyle('PRIMARY')

const message = interaction.message
const messageComponents = await message.components[0].spliceComponents(0, 1, [unclaimButton])
await interaction.reply({content: "Successfully claimed channel!", ephemeral: true})
await message.edit({content: message.content, embeds: message.embeds, components: messageComponents})
})
Cog.add = new Interaction("claimTicket", async (interaction) => {
let ticket = await fetchTicketInfo({channelId: interaction.channelId})
if (ticket.claimantId) {
await interaction.reply({content: `This channel has already been claimed by <@${ticket.claimantId}>.`, ephemeral: true})
return
}

ticket.claimantId = interaction.user.id
await updateTicketInfo(ticket)

const unclaimButton = new MessageButton()
.setCustomId('unclaimTicket')
.setLabel('📝 Unclaim')
.setStyle('PRIMARY')

const message = interaction.message
const messageComponents = await message.components[0].spliceComponents(0, 1, [unclaimButton])
await interaction.reply({content: "Successfully claimed channel!", ephemeral: true})
await message.edit({content: message.content, embeds: message.embeds, components: messageComponents})
})
Not really sure if there's a solution except from waiting for a bug fix. If there is, please let me know. Thank you.
22 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 6/21/2022 in #djs-questions
Help with Slash Commands
2 replies
DIAdiscord.js - Imagine an app
Created by Batimius on 6/20/2022 in #djs-questions
'DiscordAPIError Invalid Form Body' when creating channel
Hello there. Basically, I am trying to create a text channel using the following code:
let newChannel = await interaction.guild.channels.create({
parent: admissionsTicketsCategoryId,
name: `admissions-from-${interaction.user.username.toLowerCase()}`,
type: "GUILD_TEXT",
permissionsOverwrites: [
{
id: interaction.user.id,
allow: [
"VIEW_CHANNEL",
"SEND_MESSAGES",
"EMBED_LINKS",
"ATTACH_FILES",
"READ_MESSAGE_HISTORY"
]
}
],
reason: `${interaction.user.tag} created a ticket`
})
let newChannel = await interaction.guild.channels.create({
parent: admissionsTicketsCategoryId,
name: `admissions-from-${interaction.user.username.toLowerCase()}`,
type: "GUILD_TEXT",
permissionsOverwrites: [
{
id: interaction.user.id,
allow: [
"VIEW_CHANNEL",
"SEND_MESSAGES",
"EMBED_LINKS",
"ATTACH_FILES",
"READ_MESSAGE_HISTORY"
]
}
],
reason: `${interaction.user.tag} created a ticket`
})
But whenever the code runs, I get the following error:
DiscordAPIError: Invalid Form Body
name: Could not interpret "{'parent': '988570987685613599', 'name': 'admissions-from-batimius', 'type': 'GUILD_TEXT', 'permissionsOverwrites': [{'id': '347858411897225236', 'allow': ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']}], 'reason': 'Batimius#5703 created a ticket'}" as string.
at RequestHandler.execute (C:\Users\Batman212369\Desktop\Discord Bots\LETI-Bot-V2\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\Batman212369\Desktop\Discord Bots\LETI-Bot-V2\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async GuildChannelManager.create (C:\Users\Batman212369\Desktop\Discord Bots\LETI-Bot-V2\node_modules\discord.js\src\managers\GuildChannelManager.js:157:18)
at async Interaction.callback (C:\Users\Batman212369\Desktop\Discord Bots\LETI-Bot-V2\Cogs\ticket.js:40:22)
DiscordAPIError: Invalid Form Body
name: Could not interpret "{'parent': '988570987685613599', 'name': 'admissions-from-batimius', 'type': 'GUILD_TEXT', 'permissionsOverwrites': [{'id': '347858411897225236', 'allow': ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']}], 'reason': 'Batimius#5703 created a ticket'}" as string.
at RequestHandler.execute (C:\Users\Batman212369\Desktop\Discord Bots\LETI-Bot-V2\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\Batman212369\Desktop\Discord Bots\LETI-Bot-V2\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async GuildChannelManager.create (C:\Users\Batman212369\Desktop\Discord Bots\LETI-Bot-V2\node_modules\discord.js\src\managers\GuildChannelManager.js:157:18)
at async Interaction.callback (C:\Users\Batman212369\Desktop\Discord Bots\LETI-Bot-V2\Cogs\ticket.js:40:22)
Not really sure why. If someone could help me, that would be awesome. Thank you for your time and help, I greatly appreciate it.
3 replies