Answer the question
In order to leave comments, you need to log in
How to implement deleting a message and remembering its contents for discord.js?
Hello, dear users of Habr! I am a beginner in Java scripting and node.js. I am writing a bot for Discord on discord.js. Initially I have this code:
client.on("message", message => {
if(message.content.toLowerCase()==config.prefix + "cmd")
{
message.reply("привет, введи какое-нибудь слово, я его запомню!")
}
})
Answer the question
In order to leave comments, you need to log in
Well, something like that, but it's just a super-on-the-knee version, written in a minute and a half, just to give you direction.
Please, stick the "Discord" tag, and mark the solution if it helped.
const userMessageDict = {};
const prefix = '!';
client.on('message', msg => {
if (msg.content === `${prefix}cmd`) {
userMessageDict[msg.author.id] = null;
msg.delete({ timeout = 0 })
.then(() => msg.channel.send('I will remember your next message.'));
}
else if (msg.content === `${prefix}slovo`) {
if ((typeof userMessageDict[msg.author.id]) === 'string') {
msg.channel.send(userMessageDict[msg.author.id]);
} else {
msg.channel.send('I dont have any words remembered from you yet!');
}
} else if (userMessageDict[msg.author.id] === null) {
userMessageDict[msg.author.id] = msg.content;
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question