【发布时间】:2021-02-25 23:56:53
【问题描述】:
我是代码新手,我只是想制作一个不和谐的机器人,但我发出了命令,我让我的机器人的状态可以说些什么,但没有一个起作用。它上线了,它并没有告诉我我的代码有什么问题,但它都不起作用。
代码:
const Discord = require("discord.js");
const bot = new Discord.Client();
let prefix=".";
bot.on("ready", () => {
bot.user.setStatus("idle")
console.log("lets gooo")
});
const update = () => {
bot.user.setActivity(".help | residing on " + bot.guilds.size + " Servers", { type: 'WATCHING' });
};
bot.on('ready', update);
bot.on('guildCreate', update);
bot.on('guildRemove', update);
bot.on("message", message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let messageArray = message.content.split(" ");
let command = messageArray[0];
let args = messageArray.slice(1);
if(!command.startsWith(prefix)) return;
});
if(command === `${prefix}userinfo`) {
let embed = new Discord.RichEmbed()
.setAuthor(message.author.username)
.setColor("#5ED315")
.setThumbnail( `${message.author.avatarURL}`)
.addField("Name", `${message.author.username}#${message.author.discriminator}`)
.addField("ID", message.author.id)
message.reply("check dms");
message.channel.send({embed});
};
if("command" === `${prefix}help`) {
let embed = new Discord.RichEmbed()
.addField(".help", "gives you this current information")
.setTitle("help")
.setColor("#5ED315")
.addField(".user", "gives you info about a user(currently being worked on)")
.addField(".server","gives you info about a server(currently working on it)")
.addField("link to support server","https://discord.gg/cRJk74kDvj")
.addField("invite link for bot","https://discord.com/api/oauth2/authorize?client_id=771489748651868173&permissions=8&scope=bot")
};
message.reply("here's a list of commands that i'm able to do")
message.channel.send({embed});
messageArray = message.content.split("");
let command = messageArray[0];
if(command === `${prefix}serverinfo`) {
let embed = new Discord.RichEmbed()
.setAuthor(message.author.username)
.setColor("#5ED315")
.addField("Name", `${message.guild.name}`)
.addField("Owner", `${message.guild.owner.user}`)
.addField("Server ID" , message.guild.id)
.addField("User Count", `${message.guild.members.filter(m => m.presence.status !== 'offline').size} / ${message.guild.memberCount}`)
.addField("Roles", `${message.guild.roles.size}`);
message.channel.send({embed});
};
bot.login("bot token");
为什么没有任何工作?我真的需要帮助
【问题讨论】:
-
看到您关闭
message侦听器的方式太快了,您应该在机器人连接之前出现command is not defined之类的错误。
标签: javascript discord bots