【发布时间】:2021-04-15 19:34:16
【问题描述】:
因此,如果成员没有角色,我正在尝试制作一个机器人,该机器人会在成员加入服务器一定时间后将其踢出。到目前为止,这是我的代码。请记住,我正在使用 sleep npm 插件https://www.npmjs.com/package/sleep
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const db = require('quick.db')
const sleep = require('sleep');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.log(error);
}
});
client.on("guildMemberAdd", (member) => {
member.send("Welcome to the faith garden server! Please verify in the <#685597195789008993> to verify, you can see the questions at <#765603302774669372>")
sleep.sleep("5")
if(member.guild.roles.find(role => role.name === "Member")) {
}
else if(member.guild.roles.find(role => role.name === "Pre-Member")) {
}
else if(member.guild.roles.find(role => role.name === "Alpha-Member")) {
}
else if(member.guild.roles.find(role => role.name === "Observer")) {
}
else {
member.kick
member.send("Sorry we had to kick you because you didnt respond soon enough, you can always join back since this is just a temporary kick.")
}
});
client.login(token);
我怎么知道代码不起作用是因为节点。已经在控制台中,然后我加入了 alt,什么也没发生,没有 dm,5 秒后没有踢。没有。如果您知道如何修复机器人不做任何事情,请告诉我。 :)
【问题讨论】:
-
不清楚你在这里要解决什么问题,或者你的问题的核心是什么(你的代码转储以及它“什么都不做”的声明真的不是特别描述性的)。根据How to Ask 指南为您的问题添加相关上下文。
-
我现在更深入地解释了。 @esqew
-
是否出现任何错误?
标签: javascript discord discord.js