How to check if a user is in a specific guild

Hey there, I'm trying to make a command, that invites a person to a football club. Because, I don't want anyone to join that isn't in the main server, I wanted to check if the user is in the discord. I've tried countless solutions, but nothing worked. I don't know why, but I hope that someone can help me with this problem. Here's the code
2 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
officialdatch
officialdatchOP7mo ago
const user = interaction.options.getMember('user'); const club = interaction.options.getRole('club'); const position = interaction.options.getString('position'); const guild = await interaction.client.guilds.fetch('1231641406083301458'); const mainguild = await interaction.client.guilds.fetch('1232018031736000613'); const member = await interaction.guild.members.fetch(user.id); const mainmember = await mainguild.members.fetch(user.id); const guildMember = await guild.members.cache.get(user.id);
try { const guild = await interaction.client.guilds.fetch('1231641406083301458');
if (!member) { const nothere = new EmbedBuilder() .setColor('#fc0317') .setDescription('User not found.') await interaction.reply({embeds: [nothere], ephemeral: true }) } else if (!guild) { const noguild = new EmbedBuilder() .setColor('#fc0317') .setDescription('Guild not found.') await interaction.reply({embeds: [noguild], ephemeral: true }) }
else if (member.guild.id === guild.id) { const nothere = new EmbedBuilder() .setColor('#fc0317') .setDescription('User not found on the IFF server.') await interaction.reply({embeds: [nothere], ephemeral: true }) } else if (interaction.member === user) { const nothere = new EmbedBuilder() .setColor('#fc0317') .setDescription(You can't add yourself to the club!) await interaction.reply({embeds: [nothere], ephemeral: true }) } The highlighted script is the script that I want to check if the user is in a specific guild
Want results from more Discord servers?
Add your server