Editing message

I am making a bot that will update a message every hour, the code works so far but when trying to edit the message it gives the error that the command or function is not found and wfter a bit of looking i couldn#t find the problem: Header:
const { Client, Intents, GatewayIntentBits, IntentsBitField} = require('discord.js');
const client = new Client({ intents: [IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, GatewayIntentBits.MessageContent], autoReconnect: true });
const { Client, Intents, GatewayIntentBits, IntentsBitField} = require('discord.js');
const client = new Client({ intents: [IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, GatewayIntentBits.MessageContent], autoReconnect: true });
Creating message:
countDownMsg = client.channels.cache.find(channel => channel.name === 'announcements-‧₊˚✩').send(`# NEXT STAIRCLIMB <t:${nextHourS}:R> #`);
countDownMsg = client.channels.cache.find(channel => channel.name === 'announcements-‧₊˚✩').send(`# NEXT STAIRCLIMB <t:${nextHourS}:R> #`);
Editing message:
countDownMsg.edit(`# NEXT STAIRCLIMB <t:${nextHourS}:R> #\nLast one <t:${lastHourS}:R>`)
.then(msg => console.log(`Updated the content of a message to ${msg.content}`))
.catch(console.error);
countDownMsg.edit(`# NEXT STAIRCLIMB <t:${nextHourS}:R> #\nLast one <t:${lastHourS}:R>`)
.then(msg => console.log(`Updated the content of a message to ${msg.content}`))
.catch(console.error);
Error:
C:\Discord.js\timerBot.js:14
countDownMsg.edit(`# NEXT STAIRCLIMB <t:${nextHourS}:R> #\nLast one <t:${lastHourS}:R>`)
^

TypeError: countDownMsg.edit is not a function
at Timeout.changeTime [as _onTimeout] (C:\Discord.js\timerBot.js:14:18)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)

Node.js v20.8.1
C:\Discord.js\timerBot.js:14
countDownMsg.edit(`# NEXT STAIRCLIMB <t:${nextHourS}:R> #\nLast one <t:${lastHourS}:R>`)
^

TypeError: countDownMsg.edit is not a function
at Timeout.changeTime [as _onTimeout] (C:\Discord.js\timerBot.js:14:18)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)

Node.js v20.8.1
4 Replies
d.js toolkit
d.js toolkit7mo 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!
Cat on the Mountain
there is a delay between the send and the edit of 2 seconds, i was also curious if that was the problem so i printed it out and the message was loaded with this being the start of the message object:
Promise {
<ref *1> Message {
channelId: 'xxxxx',
guildId: 'xxxxx',
id: 'xxxx',
createdTimestamp: 1717054848197,
type: 0,
system: false,
content: '# NEXT STAIRCLIMB <t:1717054860:R> #',
author: ClientUser {
Promise {
<ref *1> Message {
channelId: 'xxxxx',
guildId: 'xxxxx',
id: 'xxxx',
createdTimestamp: 1717054848197,
type: 0,
system: false,
content: '# NEXT STAIRCLIMB <t:1717054860:R> #',
author: ClientUser {
and await just breaks it?
countDownMsg = await client.channels.cache.find(channel => channel.name === 'announcements-‧₊˚✩').send(`# NEXT STAIRCLIMB <t:${nextHourS}:R> #`);
^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1153:20)
at Module._compile (node:internal/modules/cjs/loader:1205:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47
countDownMsg = await client.channels.cache.find(channel => channel.name === 'announcements-‧₊˚✩').send(`# NEXT STAIRCLIMB <t:${nextHourS}:R> #`);
^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1153:20)
at Module._compile (node:internal/modules/cjs/loader:1205:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47
d.js docs
d.js docs7mo ago
Resources to understand Promise: - MDN: learn more - Guide: learn more - JavaScript info: learn more
Cat on the Mountain
but even if the message is loaded it still says that .edit is not a function, i also tried editMessage which i found somewhere else, didn't work either yeah it was still a promise but already had the or something, it's fixed now, thanks
Want results from more Discord servers?
Add your server