Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

How to create discord.js ping command?

I am using discord.js version 12. I have checked the docs already, it's kind of confusing.

const Discord = require("discord.js")
const client = new Discord.Client()
client.login(process.env.TOKEN)

This is my current code

question from:https://stackoverflow.com/questions/65946653/how-to-create-discord-js-ping-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is a simple ping command

const Discord = require("discord.js");
const client = new Discord.Client();

client.on("message", (message) => {
  if (message.content === '!ping') {
    message.channel.send("Pinging ...")
      .then((msg) => {
        msg.edit("Pong: " + (Date.now() - msg.createdTimestamp) + "ms")
      });
  }
})

client.login("TOKEN")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...