I'm trying to make a level bot in Discord. Basically, what I want to do is to assign a "pts" variable to every person in the server. I have an event handler and command handler in my bot.
Here is my event_handler.js:
const fs = require('fs');
module.exports = (client, Discord) =>{
const load_dir = (dirs) =>{
const event_files = fs.readdirSync(`./events/${dirs}`).filter(file => file.endsWith('.js'));
for (const file of event_files) {
const event = require(`../events/${dirs}/${file}`);
const event_name = file.split('.')[0];
client.on(event_name, event.bind(null, Discord, client));
}
}
['client', 'guild'].forEach(e => load_dir(e));
}
And here is my command_handler.js:
const fs = require('fs');
module.exports = (client, Discord) =>{
const command_files = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'))
for(const file of command_files){
const command = require(`../commands/${file}`);
if(command.name){
client.commands.set(command.name, command);
} else {
continue;
}
}
}
I also have a guildMemberAdd event, which has a guildMember variable, adds a Member role to the guildMember, and say a welcome message. Here it is (it's called guildMemberAdd.js):
module.exports = (Discord, client, guildMember) =>{
let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'Member');
guildMember.roles.add(welcomeRole);
guildMember.guild.channels.cache.get(MYCHANNELID).send(`Welcome, <@${guildMember.user.id}>, to our server! ... Check out the rules-cmd channel!`);
}
I was thinking maybe when somebody joins the server I can give them a variable. For example:
module.exports = (Discord, client, guildMember) =>{
var pts = new guildMember;
let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'Member');
guildMember.roles.add(welcomeRole);
guildMember.guild.channels.cache.get(MYCHANNELID).send(`Welcome, <@${guildMember.user.id}>, to our server! ... Check out the rules-cmd channel!`);
}
...but I'm really bad with javaScript and that, I know, will DEFINITELY not work.
Is there a way to do this? If there, is, how do I change it based on a command? (My commands are stored in another folder.)
If you guys need it, here is my ... um ... ordering of files and folders. I'm not really sure what that's called.
HELP IS GREATLY APPRECIATED!!
I don't think you guys need the node module files, right? If you do, please comment.
MY EDIT 1 (BY TYRCNEX): Some of you viewing this question might be saying, "Well there should be other Stack Overflow questions like this, right?" Yes, there is. However, I am a COMPLETE beginner with JS, as I mentioned above. I could spend a year trying to learn the basics of js...
...but I don't have that much time on my hands. I need help with my SPECIFIC problem, and I can't really understand other answers. This is why I'm asking the question. Thank you.
question from:
https://stackoverflow.com/questions/66062947/discord-bot-can-i-use-guildmember-to-create-a-personal-variable