Kiwi
Kiwi
DIAdiscord.js - Imagine an app
Created by Kiwi on 9/29/2024 in #djs-questions
Getting message context after modal submission best practice
No description
4 replies
DIAdiscord.js - Imagine an app
Created by Kiwi on 9/28/2024 in #djs-questions
How do I make a Message Context Action
Currently I have:
const logSearchContextMenu = new ContextMenuCommandBuilder()
.setName('Get Time')
.setType(ApplicationCommandType.Message);
const logSearchContextMenu = new ContextMenuCommandBuilder()
.setName('Get Time')
.setType(ApplicationCommandType.Message);
I don't get any errors or warnings, but I feel like just building it doesn't actually register it with Discord. I'm not seeing the context action on any messages in the server the bot is in. I'm following this guide: https://discordjs.guide/interactions/context-menus.html#registering-context-menu-commands I have this to handle it in my "interactionCreate" handler:
if(commandName === "Get Time")
{
interaction.reply({
content: `${interaction.targetMessage.createdAt}`,
ephemeral: true
})
}
if(commandName === "Get Time")
{
interaction.reply({
content: `${interaction.targetMessage.createdAt}`,
ephemeral: true
})
}
But I can't get the context action to even show up to test it. I feel like I'm missing something basic.
18 replies
DIAdiscord.js - Imagine an app
Created by Kiwi on 6/30/2024 in #djs-questions
Best practices for using Discord.js throughout different components
I'm working on breaking apart the single multiple thousand line .js source file I've been playing with for a while, I've seen some different advice (people saying to just make a new Discord client for each file, people exporting functions to interact with it, or exporting the client directly) and I'm not sure if my usecase is the same. Right now, I'm just trying to get my server component separated (not related to D.js) but there are a few important events I like to log to a Discord channel (so I don't have to open any additional things to monitor it). The only thing I would like to export for my bot file is the channels I like to long to so I can call .send() on them. I'm running into Warning: Accessing non-existent property 'wgConsoleChannel' of module exports inside circular dependency when loading my bot up, and Cannot read properties of undefined (reading 'send') when calling wgConsoleChannel.send() Should I export my bot, create some kind of interface for this kind of thing, or create a new Discord.Client in every file I need to do something like this? I'd prefer the lightest weight possible option (within reason)
// bot.js
let wgConsoleChannel;

const bot = new Client({
autoReconnect: true,
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Intents.FLAGS.GUILD_WEBHOOKS, Intents.FLAGS.GUILD_INVITES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_SCHEDULED_EVENTS]
});

bot.on('ready', async () =>
{
wgConsoleChannel = bot.channels.cache.get('547950347814174720')
wgInGameChannel = bot.channels.cache.get('998789095880925194')
wgKillsChannel = bot.channels.cache.get('999125728786395166')
tripInfoChannel = bot.channels.cache.get('1004134753437503580')
});

exports = { wgConsoleChannel, wgInGameChannel, wgKillsChannel, tripInfoChannel }
// bot.js
let wgConsoleChannel;

const bot = new Client({
autoReconnect: true,
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Intents.FLAGS.GUILD_WEBHOOKS, Intents.FLAGS.GUILD_INVITES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_SCHEDULED_EVENTS]
});

bot.on('ready', async () =>
{
wgConsoleChannel = bot.channels.cache.get('547950347814174720')
wgInGameChannel = bot.channels.cache.get('998789095880925194')
wgKillsChannel = bot.channels.cache.get('999125728786395166')
tripInfoChannel = bot.channels.cache.get('1004134753437503580')
});

exports = { wgConsoleChannel, wgInGameChannel, wgKillsChannel, tripInfoChannel }
// server.js
const {wgConsoleChannel, wgInGameChannel, wgKillsChannel, tripInfoChannel } = require('../bot.js')
// server.js
const {wgConsoleChannel, wgInGameChannel, wgKillsChannel, tripInfoChannel } = require('../bot.js')
Thanks for reading :)
3 replies
DIAdiscord.js - Imagine an app
Created by Kiwi on 10/22/2022 in #djs-questions
Is there a way to check if a channel already has an active event on it?
D.js v13.6.0 node v16.31.1 - Looking for a way to check if an event is already active in a channel before setting another event tied to that channel as active.
3 replies