ECS Test Fluxer Bot 1.0.1
This commit is contained in:
48
index.js
Normal file
48
index.js
Normal file
@@ -0,0 +1,48 @@
|
||||
require("dotenv").config();
|
||||
const { Client, Events } = require("@fluxerjs/core");
|
||||
|
||||
const client = new Client();
|
||||
|
||||
// Your specific IDs for your server, make sure to set these in your .env file
|
||||
const AUTO_ROLE_ID = process.env.AUTO_ROLE_ID;
|
||||
const WELCOME_CHANNEL_ID = process.env.WELCOME_CHANNEL_ID;
|
||||
const BOT_TOKEN = process.env.BOT_TOKEN;
|
||||
|
||||
// Safety check before attempting to log in
|
||||
if (!BOT_TOKEN) {
|
||||
console.error(
|
||||
"CRITICAL ERROR: BOT_TOKEN is missing or undefined. Check your .env file!",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
client.on(Events.Ready, () => {
|
||||
/* This will log the bot's username and discriminator to the console when it successfully logs in
|
||||
* For some reason, client.user.tag doesn't work, so we have to concatenate the username and discriminator manually.
|
||||
*/
|
||||
console.log(`Online! Logged in as ${client.user.username}#${client.user.discriminator}`);
|
||||
});
|
||||
|
||||
client.on(Events.GuildMemberAdd, async (member) => {
|
||||
try {
|
||||
await member.roles.add(AUTO_ROLE_ID);
|
||||
console.log(`Assigned role to ${member.user.username}`);
|
||||
|
||||
const welcomeChannel =
|
||||
await member.guild.channels.fetch(WELCOME_CHANNEL_ID);
|
||||
if (welcomeChannel) {
|
||||
// This is my example for my server welcome message, feel free to change it up to fit your server's vibe!
|
||||
await welcomeChannel.send(
|
||||
`Eh Bro! Welcome to the Hub, <@${member.user.id}>! Grab a seat and say hello. You also have the Role ${member.guild.roles.cache.get(AUTO_ROLE_ID).name} now, so you can check out the channels and get involved!`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to handle join event for ${member.user.username}:`,
|
||||
error,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Log in
|
||||
client.login(BOT_TOKEN);
|
||||
Reference in New Issue
Block a user