discord.js message in a function

how can i make a function that i can xall at any time and it will alow me to send a certain message
4 Replies
d.js toolkit
d.js toolkit10mo 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!
d.js docs
d.js docs10mo ago
mdn async function The async function declaration creates a binding of a new async function to a given name. The await keyword is permitted within the function body, enabling asynchronous, promise-based behavior to be written in a cleaner style and avoiding the need to explicitly configure promise method TextChannel#send() Sends a message to this channel.
MrAxeman6
MrAxeman610mo ago
this is the function at the minute and it says that the channel cant be found: function dcnotifacation(channelId, msg){ // Find the channel by its ID const guild = dcclient.guilds.cache.first(); // Get the first guild (server) the bot is in const channel = guild.channels.cache.get(channelId); if (!channel) { console.error('Channel not found'); return; // Exit the function early } // Send the message to the channel channel.send(msg) .then(() => { console.log('Message sent successfully'); }) .catch(error => { console.error('Error sending message:', error); }); no after but it is doing it befor this is the way i have the code dcclient.login(process.env.BOT_TOKEN) dcnotifacation('1150042953012740148', "ONLINE: ATF Tracking System") dcnotifacation is the function i am trying to make i go in also it is having an eoor with the word guilds
Squid
Squid10mo ago
Unless you await the dccilent.login(...), the dcnotification(...) function may be called first since the former is an asynchronous function You should move the dcnotification(...) to your ready event listener so it will only be called after the Client is ready