简体   繁体   中英

Discord.js how can I send message and check server id

"Discord.js version 11.4.2"

I have a question if I want to create a command such as command check server id if server id is 426626817596850177 then it will send a message to channel "verify server" if id server isn't 426626817596850177 then "can't verify server"

if(message.content === "a check"){
  const msg = await message.channel.send("Checking Server.....")
  msg.edit("verify server")
}

Just simplified Ciphers answer a little

if(message.content === "a check"){
    const msg = await message.channel.send("Checking Server.....")
    if (message.guild.id == 426626817596850177) {
      msg.edit("verify server");
    } else {
      msg.edit("can't verify server");
    };
  };

You can use message.guild.id for this. I use array of guild`s id because maybe more then 1 server can be verified.

client.on('message', message => {
    if (message.content === 'a check') {
        message.channel.send('Checking Server.....').then(msg => {
            if (['426626817596850177'].includes(message.guild.id)) {
                msg.edit('verify server');
            } else {
                msg.edit("can't verify server");
            }
        });
    }
});

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