因此,我为我的不和谐的机器人开了一个活动手,这样,指数.js文档就子了。 但出于某种原因,当有人加入服务器时,我发出令人欢迎的信息。
这里我的活动手法:
const eventFiles = fs.readdirSync( ./events ).filter(file => file.endsWith( .js ));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, Discord, client));
} else {
client.on(event.name, (...args) => event.execute(...args, Discord, client));
}
}
而且 在我欢迎的致词中:
module.exports = {
name: welcome ,
once: false,
execute(Discord, client) {
const welcomechannelId = 753484351882133507 //Channel You Want to Send The Welcome Message
const targetChannelId = `846341557992292362` //Channel For Rules
client.on( guildMemberAdd , (member) => {
let welcomeRole = member.guild.roles.cache.find(role => role.name === Umay );
member.roles.add(welcomeRole);
const channel = member.guild.channels.cache.get(welcomechannelId)
const WelcomeEmbed = new Discord.MessageEmbed()
.setTitle(`Welcome To ${member.guild.name}`)
.setThumbnail(member.user.displayAvatarURL({dynamic: true, size: 512}))
.setDescription(`Hello <@${member.user.id}>, Welcome to **${member.guild.name}**. Thanks For Joining Our Server.
Please Read ${member.guild.channels.cache.get(targetChannelId).toString()}, and assign yourself some roles at <#846341532520153088>. You can chat in <#753484351882133507> and talk with other people.`)
// You Can Add More Fields If You Want
.setFooter(`Welcome ${member.user.username}#${member.user.discriminator}`,member.user.displayAvatarURL({dynamic: true, size: 512}))
.setColor( RANDOM )
member.guild.channels.cache.get(welcomechannelId).send(WelcomeEmbed)
})
}
}
我没有错误,但是,如果有人加入服务器,他/她就没有被赋予作用,欢迎的信息就没有出现。 我把欢迎的信息编码放在一个事件上,即活动手正在处理。 谁能帮助?