How do I edit a message using message.edit()?

Currently, here's my code:
// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits } = require('discord.js');
const dotenv = require('dotenv')
const repl = require('repl')
const commands = require('./commands')
dotenv.config()
var message;
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
let channel;
// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
channel = client.channels.cache.get('1053340012021821593');
});
client.login(process.env.token);
const prompt = repl.start({
prompt: "Message to send: ",
eval: function(cmd,context,filename,callback){
message = channel.send(cmd)
this.displayPrompt()
}
})
prompt.defineCommand('test',{
help: "Test command",
action(newMessage){
message.edit(newMessage)
.then()
.catch(console.log(e))
},
})
// Log in to Discord with your client's token
// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits } = require('discord.js');
const dotenv = require('dotenv')
const repl = require('repl')
const commands = require('./commands')
dotenv.config()
var message;
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
let channel;
// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
channel = client.channels.cache.get('1053340012021821593');
});
client.login(process.env.token);
const prompt = repl.start({
prompt: "Message to send: ",
eval: function(cmd,context,filename,callback){
message = channel.send(cmd)
this.displayPrompt()
}
})
prompt.defineCommand('test',{
help: "Test command",
action(newMessage){
message.edit(newMessage)
.then()
.catch(console.log(e))
},
})
// Log in to Discord with your client's token
16 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
ah yes the error: here it is:
node:internal/readline/emitKeypressEvents:71
throw err;
^

TypeError: message.edit is not a function
at REPLServer.action (C:\Users\esmit\source\repos\Visual-Studio-Code-Projects\gamebot\bot.js:27:17)
at REPLServer._parseREPLKeyword (node:repl:806:7)
at REPLServer.onLine (node:repl:888:13)
at REPLServer.emit (node:events:513:28)
at REPLServer.emit (node:domain:489:12)
at REPLServer.Interface._onLine (node:readline:491:10)
at REPLServer.Interface._line (node:readline:868:8)
at REPLServer.Interface._ttyWrite (node:readline:1220:14)
at REPLServer.self._ttyWrite (node:repl:997:9)
at ReadStream.onkeypress (node:readline:291:10)
node:internal/readline/emitKeypressEvents:71
throw err;
^

TypeError: message.edit is not a function
at REPLServer.action (C:\Users\esmit\source\repos\Visual-Studio-Code-Projects\gamebot\bot.js:27:17)
at REPLServer._parseREPLKeyword (node:repl:806:7)
at REPLServer.onLine (node:repl:888:13)
at REPLServer.emit (node:events:513:28)
at REPLServer.emit (node:domain:489:12)
at REPLServer.Interface._onLine (node:readline:491:10)
at REPLServer.Interface._line (node:readline:868:8)
at REPLServer.Interface._ttyWrite (node:readline:1220:14)
at REPLServer.self._ttyWrite (node:repl:997:9)
at ReadStream.onkeypress (node:readline:291:10)
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
how
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
i mean like what do i put inside the .then?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
so then you save it as message?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
i had it saved as a variable called message, so it would be with the msg param message = msg;
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
ok so you don't want me to add the promise and just do message = channel.send(msg)?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
i'm gonna guess that's a yes and it's still same error, would it be channel.message.edit? just a guess tho
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
here's what i'm doing to try to save the message (probably definetly not correct): channel.send(cmd).then(message) oh i got it working

Did you find this page helpful?