我在制造不和。jsbot,但我想为应用程序添加更多命令。例如,我想要一个命令!应用1
和命令!应用程序2
。当我复制代码、再次粘贴、更改命令名称并键入命令时,它会发送两到三个问题,而不是一个问题。我应该换什么?
如果你不明白,想检查我在说什么,加入这个假的不和谐服务器:https://discord.gg/fVsQaa6(每次发送2个问题,我想发送1个1个。此外,它将答案发送到他们两个的相同通道,我检查了通道ID是否正确,它是。)
守则:
// Requires \\
const botSettings = require("./botsettings.json");
const Discord = require("discord.js");
const prefix = botSettings.prefix;
const bot = new Discord.Client({disableEveryone: true});
// Bot On Ready Console \\
bot.on('ready', () => {
console.log("Bot Is Ready");
bot.user.setActivity("Great", {type: "WATCHING"})
})
// Staff \\
let userApplications = {}
bot.on("message", function(message) {
if (message.author.equals(bot.user)) return;
let authorId = message.author.id;
if (message.content === "!apply staff") {
console.log(`Apply begin for authorId ${authorId}`);
if (!(authorId in userApplications)) {
userApplications[authorId] = { "step" : 1}
message.author.send(" ")
message.author.send(">>> Staff Application")
message.author.send(">>> Question 1:");
}
} else {
if (message.channel.type === "dm" && authorId in userApplications) {
let authorApplication = userApplications[authorId];
if (authorApplication.step == 1 ) {
authorApplication.answer1 = message.content;
message.author.send(">>> Question 2:");
authorApplication.step ++;
}
else if (authorApplication.step == 2) {
authorApplication.answer2 = message.content;
message.author.send(">>> Question 3:");
authorApplication.step ++;
}
else if (authorApplication.step == 3) {
authorApplication.answer3 = message.content;
message.author.send(">>> Question 4:");
authorApplication.step ++;
}
else if (authorApplication.step == 4) {
authorApplication.answer4 = message.content;
message.author.send(">>> Question 5:");
authorApplication.step ++;
}
else if (authorApplication.step == 5) {
authorApplication.answer5 = message.content;
message.author.send(">>> Question 6:");
authorApplication.step ++;
}
else if (authorApplication.step == 6) {
authorApplication.answer6 = message.content;
message.author.send(">>> Question 7:");
authorApplication.step ++;
}
else if (authorApplication.step == 7) {
authorApplication.answer7 = message.content;
message.author.send(">>> Question 8:");
authorApplication.step ++;
}
else if (authorApplication.step == 8) {
authorApplication.answer8 = message.content;
message.author.send(">>> Thank You!");
bot.channels.cache.get("743550883589259287")
.send(`${message.author}\n >>> Question 1: | ${authorApplication.answer1}\n Question 2: | ${authorApplication.answer2}\n Question 3: | ${authorApplication.answer3}\n Question 4: | ${authorApplication.answer4}\n Question 5: | ${authorApplication.answer5}\n Question 6: | ${authorApplication.answer6}\n Question 7: | ${authorApplication.answer7}\n Question 8: | ${authorApplication.answer8}`);
delete userApplications[authorId];
}
}
}
});
// Police \\
bot.on("message", function(message) {
if (message.author.equals(bot.user)) return;
let authorId = message.author.id;
if (message.content === "!apply police") {
console.log(`Apply begin for authorId ${authorId}`);
if (!(authorId in userApplications)) {
userApplications[authorId] = { "step" : 1}
message.author.send(" ")
message.author.send(">>> Police Application")
message.author.send(">>> Question 1:");
}
} else {
if (message.channel.type === "dm" && authorId in userApplications) {
let authorApplication = userApplications[authorId];
if (authorApplication.step == 1 ) {
authorApplication.answer1 = message.content;
message.author.send(">>> Question 2:");
authorApplication.step ++;
}
else if (authorApplication.step == 2) {
authorApplication.answer2 = message.content;
message.author.send(">>> Question 3:");
authorApplication.step ++;
}
else if (authorApplication.step == 3) {
authorApplication.answer3 = message.content;
message.author.send(">>> Question 4:");
authorApplication.step ++;
}
else if (authorApplication.step == 4) {
authorApplication.answer4 = message.content;
message.author.send(">>> Question 5:");
authorApplication.step ++;
}
else if (authorApplication.step == 5) {
authorApplication.answer5 = message.content;
message.author.send(">>> Question 6:");
authorApplication.step ++;
}
else if (authorApplication.step == 6) {
authorApplication.answer6 = message.content;
message.author.send(">>> Question 7:");
authorApplication.step ++;
}
else if (authorApplication.step == 7) {
authorApplication.answer7 = message.content;
message.author.send(">>> Question 8:");
authorApplication.step ++;
}
else if (authorApplication.step == 8) {
authorApplication.answer8 = message.content;
message.author.send(">>> Thank You!");
bot.channels.cache.get("743558960677912636")
.send(`${message.author}\n >>> Question 1: | ${authorApplication.answer1}\n Question 2: | ${authorApplication.answer2}\n Question 3: | ${authorApplication.answer3}\n Question 4: | ${authorApplication.answer4}\n Question 5: | ${authorApplication.answer5}\n Question 6: | ${authorApplication.answer6}\n Question 7: | ${authorApplication.answer7}\n Question 8: | ${authorApplication.answer8}`);
delete userApplications[authorId];
}
}
}
});
bot.login(botSettings.token);
我很确定它一次发送两条消息,因为您可能会让代码编辑器和命令提示符同时运行代码。这是很平常的事。你的代码看起来很正常,所以我很确定事情就是这样。
你的两个客户都有else语句。关于(“消息”)执行。
如果您决定对bot进行dm,它将检查第一个条件:If(message.content==“!apply staff”)
,第二个条件:If(message.content==“!apply police”)
。
由于两者都是假的,机器人将执行这两种语句。这就是为什么你每次会有两个问题。
如果您想解决这个问题,存储应用程序值,然后在else语句中检查它,或者合并两个客户机,这可能会很有趣。on(“message”)并在else语句中添加一个检查。
Red Discord Bot 是一个完全模块化的机器人,意味着所有的功能和命令都可以根据你的喜好来启用/禁用,使其完全可定制。这是一个自托管的机器人,你需要托管和维护你自己的实例。你可以把 Red 变成一个管理机器人、音乐机器人、事务处理机器人等。 默认的模块集包括但不限于: 管理功能(踢人/禁言、管理日志、过滤器、聊天清理) 音乐功能(YouTube、SoundCloud、本地文件、播放列表、
Discord Music Bot 是一个先进的 Discord 音乐机器人,支持 Spotify、Soundcloud、YouTube,以及带有随机播放、音量控制功能和带有 Slash Command 支持的 Web 仪表板。 要求 Node.js 14+ discord.js@12.5.3 Lavalink Server Discord.js v13 会破坏这个机器人,因此不要用它。
我将如何做出反应角色事件。这是我试过的代码 我想做的是让我的机器人检查对特定消息的反应,然后给用户一个角色,如果他们的反应是正确的表情符号。
我一直在用 命令代码。我希望它能回复“你好!很高兴见到你!”当我说的时候!你好(!=前缀)。但它什么也没回来。甚至一个错误都没有。有人知道为什么吗?另外,请不要显示discord bot不响应命令或discord命令bot不响应(python),因为我尝试了这两种方法,但都不起作用。
我有一个用Java和Gradle编码的不和谐bot,我需要找到如何使它工作。我问机器人的主人,他回答我:“./Gradlew Shadowjar”这是什么意思?我需要做什么才能让机器人正常工作? 我已经尝试过用jar编译java文件,我尝试过创建一个清单,但我不能创建类。 ->无效,错误:包ch.qos.logback.classic不存在 ->创建了一个不执行任何操作的.jar文件 ->不知道这
我通过引用这个数字海洋链接创建了一个discord机器人 现在我可以使用bot向任何频道发送消息,但我的要求是向该服务器的用户发送dm 为此,我尝试了许多答案,并通过其他链接进行了访问,但所有的解决方案最终都是相同的 我尝试了两种方法来获取公会用户并将dm发送给任何一个选定的用户 第一种方式-获取公会(服务器)的所有用户 输出 通过这种方式,它只返回bot名称本身。虽然会员人数是6。 第二种方式-