【发布时间】:2021-06-10 22:10:35
【问题描述】:
所以我正在尝试制作一个机器人来计算有人说有趣的次数并将其存储在 .json 文件中我可以让它设置 .json 并说有人说过一次但它不会高于 1。提前谢谢你,这是我的代码
const Discord = require("discord.js");
const bot = new Discord.Client();
const prefix = "!";
const token = "token";
const fs = require("fs");
Discord.Client.msg = require ("./msgs.json");
bot.on("ready", () =>{
console.log(`${bot.user.username} online`);
});
bot.on("message", msg => {
if(msg.author.bot) return;
const say = msg.content.toLowerCase()
if(say === "are you online?"){
msg.reply("I am online and ready to be a funny");
}
if(say === "v"){
msg.reply("is stupid @everyone");
}
else if (say === "funny"){
if(![msg.author.username]){
Discord.Client.msg [msg.author.username] = {
funnycount: 1
}
}
else{
Discord.Client.msg [msg.author.username] = {
funnycount: +1
}
msg.reply("it worked");
}
fs.writeFile ("./msgs.json", JSON.stringify (Discord.Client.msg, null, 4), err => {
if (err )throw err;
});
}
});
bot.on("message", msg =>{
if(!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).split(" ");
const command = args.shift().toLowerCase();
if(command == "ping"){
msg.channel.send("pong!");
}
});
bot.login(token);
【问题讨论】:
标签: javascript discord discord.js