#djs storing data
23 messages · Page 1 of 1 (latest)
discord.js is a library for interacting with the discord api, not for storage
where from? thats very much outdated
but this is for v12. in v14, it's a bit different
listen on the messageCreate event, process the user message then send it back
(event) Client#messageCreate
Emitted whenever a message is created.
your JS knowledge seems very limited, so idk how to help you
Are you trying to store data in like a database or you want to make a block based variable that will be initiated every time the command is run ? I would of course encourage you to learn basic JS before diving into discord.js
You can find popular resources for learning in #resources
go for a .starts with '!register ' and then slice it at the space and you van take the second part for the responce
Do you mean command arguments/options? You can achieve that with slash commands: https://discordjs.guide/interactions/slash-commands.html#registering-slash-commands
It's also possible with messages but slash commands are recommended
this is what i got for something slightly simular, you'l just have to short it in to what you need
if(msg.content.startsWith('tb! ')) {
console.log('recognised')
if(msg.content.startsWith('add reaction: ', 4)){
if(msg.content.includes(';')){
const message = msg.content;
const reaction = message.slice(18);
const index = reaction.indexOf(';');
console.log(index);
const key = reaction.slice(0,index);
const value = reaction.slice(index+1);
reactions[key] = value;
console.log('reaction added');
console.log(reactions);
}else{
msg.channel.send("no divider: ';'")
}
}
}
Here's an old command handler as well for reference
https://v12.discordjs.guide/command-handling/#dynamically-executing-commands
Then you can use args[0] for the first argument, 1 for 2nd, etc.
They are separated by spaces
And to get things after space as well you can use for example args[1].join(" ")
But it's still better to use slash commands instead
They have all those options built-in
this remade to your needs would be a 5 line code like this:
||
if(msg.content.startsWith('!register')) {
const message = msg.content;
const name = message.slice(10);
message.channel.send('Hello'+name);
}||
op already solved their problem, so this should be closed anyway