我使用的是discord.js版本12。我已经检查过文档了,有点混乱。
const Discord = require("discord.js")
const client = new Discord.Client()
client.login(process.env.TOKEN)这是我当前的代码
发布于 2021-01-29 07:25:28
这是一个简单的ping命令
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")发布于 2021-01-29 07:38:59
简单的命令!我们正在做的就是让事情变得更美好!
现在您创建了一个消息事件,如果消息是"! ping“,它将使用bot ping进行回复!我们将使用discord.js模块中的类"MessageEmbed“。这个类允许我们创建漂亮和平滑的嵌入!
此外,您不需要所有的discord.js模块,只需像下面的示例那样从其中获取类!
还要将client.login(process.env.TOKEN)放在主/index.js文件的末尾
// Requiring the client and message embed objects from discordjs module
const { Client, MessageEmbed } = require('discord.js');
// New discordjs client
const client = new Client(); // Name it as you want
// Ready event !
client.on("ready", () => {
// Sends something to the console to say that the bot is ready to work !
console.log("The bot is connected !")
});
client.on("message", message => {
// Ping command !
if(message.content === "!ping") {
// New embed for the bot ping !
const embed = new Discord.MessageEmbed()
.setDescription(`**? My ping is : **\`${Math.round(client.ws.ping)}ms\``)
// Now we send the embed to our channel !
message.channel.send(embed)
} // End of our command code !
})
// Now logs in the bot using your token (keep secret !)
client.login(process.env.TOKEN)发布于 2021-02-01 16:40:58
client.on("message", (message) => {
if (message.content === '!ping') {
message.channel.send("Latency is ${Date.now() - message.createdTimestamp}ms`")
});
}
})https://stackoverflow.com/questions/65946653
复制相似问题