A
A
Alexander2020-05-28 16:24:22
JavaScript
Alexander, 2020-05-28 16:24:22

How to make the command work only after the bot message?

It is required that the bot writes for example "Type !next to continue", and the command works only after this message (it should not work without it).
I don't understand how it works, please point me in the right direction.
Thanks in advance to everyone for the replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DeityLamb, 2020-05-28
@Alexandre888

First you need to decide whether you need to know what the person wrote next, in the long run. If this is not so important, and most likely tomorrow he will not remember that he wrote this command, then it will be enough to write this information into some kind of cache. If not. Then you write it to the database.
Let's look at the cache option. By analogy, you can link it to your database if needed.
I'm assuming you're using the discord.js module and I'll write explanations for it.
For convenience, we can write this data directly to an instance of the GuildMember class so that it works on every discord server.
for the cache, we can create a cache object directly in an instance of the class, and we will write data to the properties of this object that will be stored in the short term. There are 2 options.
1 - Check if an instance of the class has such a property in the context, if not. Then create it. And then write the necessary data to it.
2 - At the prototype level, when the library itself adds an instance of the class to the cache, create an object.

//1
if(!(member.cache && member.cache.nexted !== undefined)) member.cache = {
    nexted: false // по дефолту false
}
//В таком случае каждый раз когда ты будешь использовать кэш, нужно будет делать проверку 

//2
const { GuildMember } = require('discord.js')
Object.defineProperty(GuildMember.prototype, {
    configurable: true,
    value: {
        nexted: false
    }
})
//В таком случае по дефолту каждый экземпляр класса GuildMember будет содержат в себе такой объект

and after the !next command, we simply change nexted to true.
And in the command itself, if we have the value nexted - false, then we just let's throw a message into the chat, well, or do nothing.
otherwise, if nexted is true, then we continue executing the command
and after it is executed, we set the value of nexted back to false.
well, that's all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question