Checking roles of user in server from their dm message

i want to check if a user dms and also has a role in the server
if ((message.channel.type == 1) && member.roles.cache.has('1093515437792305222'))
console.log("dm'd with role")
if ((message.channel.type == 1) && member.roles.cache.has('1093515437792305222'))
console.log("dm'd with role")
i tried this first but then realised if its in a dm you have no roles, is there a way around this? this bot will only be used in one server
47 Replies
d.js toolkit
d.js toolkit16mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Fxkitt
Fxkitt16mo ago
the bot dms them when they get the role and then i want the reply to change their nickname and remove the role if they have it
d.js docs
d.js docs16mo ago
Tag suggestion for @fxkitt: Despite sounding similar there is a distinct difference between users and members in Discord: • User: global Discord user data (global avatar, username, tag, id) • GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.) • Conversion: User ➞ GuildMember | GuildMember ➞ User
Fxkitt
Fxkitt16mo ago
@Deleted User i cant actually use these links
Fxkitt
Fxkitt16mo ago
got the url up there but it just takes me to that and then clicking docs takes me to a page where i cant search anything
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
how would guild.members.fetch(author.id) know which guild to check its only in one server tho so will it just check the one its in? or do i need to set a variable
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
so i need to do guild = client.guilds.cache.get('guild id')
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
awesome ty
Fxkitt
Fxkitt16mo ago
sumn like this work?
Fxkitt
Fxkitt16mo ago
didnt work hmm oh message.author
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
Fxkitt
Fxkitt16mo ago
think theres an issue here as this doesnt work
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
this is an issue before doing fetch tho
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
// Require the necessary discord.js classes

const { token } = require('./config.json');

// Create a new client instance

const Discord = require('discord.js');
const settings = require('./config.json');

const { Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessageTyping,
],
partials: [Partials.Channel],
});

client.on('ready', () => {
console.log("- Bot logged in -");
});
client.on('guildMemberUpdate', (oldMember, newMember) => {

const oldRoles = oldMember.roles.cache,
newRoles = newMember.roles.cache;

// Has Role?
const oldHas = oldRoles.has('1093515437792305222'),
newHas = newRoles.has('1093515437792305222');

// Check if removed
if (!oldHas && newHas) {
newMember.user.send("Please enter your nickname")
}
});
client.on('messageCreate', async (message) => {
console.log(message.channel.type)

if (message.channel.type == 1) {
console.log("dm recieved")
const guild = client.guilds.cache.get('975539628855660575')
console.log(guild.members.fetch(message.author.id))
//if guild.members.fetch(author.id).roles.cache.has('1093515437792305222'))
//console.log("dm'd with role")
}


}
});

client.login(settings.token);

// start
// Require the necessary discord.js classes

const { token } = require('./config.json');

// Create a new client instance

const Discord = require('discord.js');
const settings = require('./config.json');

const { Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessageTyping,
],
partials: [Partials.Channel],
});

client.on('ready', () => {
console.log("- Bot logged in -");
});
client.on('guildMemberUpdate', (oldMember, newMember) => {

const oldRoles = oldMember.roles.cache,
newRoles = newMember.roles.cache;

// Has Role?
const oldHas = oldRoles.has('1093515437792305222'),
newHas = newRoles.has('1093515437792305222');

// Check if removed
if (!oldHas && newHas) {
newMember.user.send("Please enter your nickname")
}
});
client.on('messageCreate', async (message) => {
console.log(message.channel.type)

if (message.channel.type == 1) {
console.log("dm recieved")
const guild = client.guilds.cache.get('975539628855660575')
console.log(guild.members.fetch(message.author.id))
//if guild.members.fetch(author.id).roles.cache.has('1093515437792305222'))
//console.log("dm'd with role")
}


}
});

client.login(settings.token);

// start
if (message.channel.type == 1) {
console.log("dm recieved")
if (message.channel.type == 1) {
console.log("dm recieved")
isnt working
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
oh didnt see that sorry ill try that oh wait no
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
ive done that
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
1
Fxkitt
Fxkitt16mo ago
Fxkitt
Fxkitt16mo ago
Fxkitt
Fxkitt16mo ago
got it to work
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
Fxkitt
Fxkitt16mo ago
did that
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
idk how that works but it did ig
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
thats what im thinking rn
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
oh
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
Fxkitt
Fxkitt16mo ago
that right?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
ohh before guild? do i also need to put ; at end of each line in if statements? i dont think i did that either
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
is discord py hard to set up i realised after getting discord js that theres a python version
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Fxkitt
Fxkitt16mo ago
im very experienced with python so that might be smarter