DJ E BEATZ
DIAdiscord.js - Imagine an app
•Created by DJ E BEATZ on 6/13/2024 in #djs-questions
help with bot
I am trying to code my bot so that when a member of my sever pickes a role they get added to a specific thread channel. For example if they pick the English role they get add to all of the English threads, if they pick the Spanish role they get added to all of the Spanish roles, etc. I am having trouble figuring out the code to do this. I am new to coding so I am having a hard time understanding some of the terminology used on the discord.js website when I tried to do this on my own. If anyone could possibly lead me in the right direction I would really appreciate it. If someone could also take a look at my code and see if what I have is in the right direction please. So far this is what I got for my code:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log('Logged in as ${client.user.tag}!');
// Get the thread channel
const threadChannel = client.channels.cache.get('thread-channel-id');
// Get the member to add
const member = client.users.cache.get('member-id');
// Get the role to add
const role = client.guilds.cache.get('guild-id').roles.cache.get('role-id');
// Add the member to the thread with the role
threadChannel.addMember(member, role).then(() => {
console.log('Member added to thread with role!');
}).catch(err => {
console.log('Error adding member to thread:', err);
});
});
client.login('bot-token');
16 replies