How to properly get channel ID?

Hello, all I really want to do is to get the channel ID, but I'm struggling to do so as it prints out as undefined. module.exports = async ( interaction, client, member) => { const channelID = interaction.channel?.id; console.log(channelID); /if (channel.id === '852196626138267698') { console.log('works!'); }/ }
19 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Danial
Danial14mo ago
How are you calling this function? Is it a guild channel or a DM channel? Does the bot have Guilds intent?
anti
antiOP14mo ago
I'm using commandkit, which is a handler for commands and events. Im trying to get the guild channel id and the bot does have the necessary intent. new CommandKit({ client, //client commandsPath: path.join(dirname, 'commands'), //path to commands eventsPath: path.join(dirname, 'events'), //path to events validationsPath: path.join(__dirname, 'validations'), //path to validations devGuildIds: ['852010387795607562'], devRoleIds: [ '852199048970108959', //loser '852213887956680795', //nsfw '884877160668602409', //manga enthusiast '852201577548742687' //anime ], skipBuiltInValidations: false, }); ^^^ The function calling for it !
d.js docs
d.js docs14mo ago
The order of function parameters must match between definition and function call.
function execute(client, interaction) { ... };
execute(interaction, client);
function execute(client, interaction) { ... };
execute(interaction, client);
- mismatch! you pass an interaction where the client is expected - mismatch! you pass the client where an interaction is expected
anti
antiOP14mo ago
I'm not quite sure but looking at commandkits docs... module.exports = (c, client, handler) => { console.log(${c.user.username} is ready!); }; "The first parameter c is the client object that was returned as a parameter when the "ready" event was triggered. The second parameter client is the Discord.js client that was instantiated in your main entry point file. Finally, the handler parameter is the current CommandKit instance." yeah, its still returning undefined.
duck
duck14mo ago
looking at the commandkit docs, it doesn't just pass the interaction as its own param examples show ({ interaction, client, handler }) => { where it's destructured
anti
antiOP14mo ago
Yup
anti
antiOP14mo ago
No description
No description
anti
antiOP14mo ago
I don't know lmao I feel like its really simple to fix but I don't understand what the issue really is from my understanding I'm not properly defining it so I'm scouring through the code to see where its not getting defined at
duck
duck14mo ago
your filepath seems to indicate that this file will have nothing to do with commands or interactions for that matter I suppose I had assumed that when you named the param interaction, that this was a command, but it appears not reactions aren't interactions <MessageReaction>.channelId doesn't exist <MessageReaction>.message.channelId does exist
anti
antiOP14mo ago
ahhh I see where could I see that on the docs? is it under messageReactions?
d.js docs
d.js docs14mo ago
property MessageReaction#message The message that this reaction refers to
anti
antiOP14mo ago
Is that the same for messageReactionadd as well>?
duck
duck14mo ago
the messageReactionAdd event emits with a MessageReaction and a User, so yes
d.js docs
d.js docs14mo ago
event (event) Client#messageReactionAdd Emitted whenever a reaction is added to a cached message.
anti
antiOP14mo ago
another question, if I were to make a reaction role, would it better to have it as a command instead, or as an event? I've noticed that when I start a new "save", it doesn't read the new reactions thats added to previous messages from the previous "saves".
duck
duck14mo ago
not exactly sure what you mean reactions are reactions they also aren't commands if you mean that you want to send the message with reactions through a command, you're free to do so you're also free to just use buttons it's entirely up to you I'm assuming that when you make the distinction between a command and an event, that'd be because commandkit is doing so, but fyi application commands are handled through the interactionCreate event if by 'new "save"' you mean a new instance of your bot, that'd be because the messages are uncached you'd need the Message and Reaction partials to listen for reactions on uncached messages as discord doesn't send all data required to fully make the associated objects
d.js docs
d.js docs14mo ago
guide Popular Topics: Reactions - Listening for reactions on old messages read more
anti
antiOP14mo ago
Alright I see, that makes sense Thanks a lot And yeah that is what I meant
Want results from more Discord servers?
Add your server