简体   繁体   中英

How can I make a command in discord.js only usable to me?

Here's my code for the section of the command:

if (message.member.id = ("566757254100156426")) {
    message.channel.send('Obtaining ping...').then(msg => {
        const ping = msg.createdTimestamp - message.createdTimestamp;
        msg.edit(`Pong! **${ping}ms**`);
    })
} else {
    message.channel.send('You do not have the right role for this command!')
}

If the id of whoever is trying to execute the command is equal to yours, do the command, otherwise send an error

if (message.member.id === '566757254100156426') {
   // command code
} else {
  // error message
}

Use:

if (message.author.id === "566757254100156426")

In JavaScript , you have to put tree equals to test equality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM