#When checking for a members role it returns null.
1 messages · Page 1 of 1 (latest)
Ok
module.exports = (client, instance) => {
client.on("messageCreate", async (message) => {
if (message.partial) await message.fetch()
const channelIDs = new Array('949756928513421312', '867771270166741043', '867773400733581353', '867773627604926464')
const roleIDs = new Array('946458813505077338', '936780720603558021', '867755665819566130')
if(!message.guild) return;
if(channelIDs.includes(message.channel.id)) return;
message.member.roles.cache.forEach(async (role) => {
if(roleIDs.includes(role.id)) return;
})
if(message.content.toLowerCase().includes("https://discord")) return;
if(message.content.toLowerCase().includes("https://")) {
message.channel.send(`${message.author} Links are disabled in this chat. `)
await message.delete();
}
})
}```
Can you log message for me and send the output here?
Error:
C:\Acquire Bot\events\chatfilteringlink.js:8
message.member.roles.cache.forEach(async (role) => {
^
TypeError: Cannot read properties of null (reading 'roles')
at Client.<anonymous> (C:\Acquire Bot\events\chatfilteringlink.js:8:24)
at Client.emit (node:events:402:35)
at MessageCreateAction.handle (C:\Acquire Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:26:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Acquire Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Acquire Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
at WebSocketShard.onPacket (C:\Acquire Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Acquire Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Acquire Bot\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:390:28)
at Receiver.receiverOnMessage (C:\Acquire Bot\node_modules\ws\lib\websocket.js:1137:20)```
Yes.
fetch?
<ref *1> Message {
channelId: '946527544650379314',
guildId: '867745424755261460',
id: '965103860614070282',
createdTimestamp: 1650169091133,
type: 'DEFAULT',
system: false,
content: 'https://',
author: User {
id: '773815660367052810',
bot: false,
system: false,
flags: UserFlags { bitfield: 0 },
username: 'Recon',
discriminator: '1234',
avatar: 'a_b2a0e0e96b312f232c059a2ff5b8a0aa',
banner: undefined,
accentColor: undefined
},
pinned: false,
tts: false,
nonce: '965103904305971200',
embeds: [],
components: [],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
editedTimestamp: null,
reactions: ReactionManager { message: [Circular *1] },
mentions: MessageMentions {
everyone: false,
users: Collection(0) [Map] {},
roles: Collection(0) [Map] {},
_members: null,
_channels: null,
crosspostedChannels: Collection(0) [Map] {},
repliedUser: null
},
webhookId: null,
groupActivityApplication: null,
applicationId: null,
activity: null,
flags: MessageFlags { bitfield: 0 },
reference: null,
interaction: null
}```
umm
wait that isnt correct
@mild pebble Fixed.
Do you want me to send ALL of what was console logged?
No, just the sent msg
perfect then that is it.
Log message.guild
<ref *2> Guild {
id: '867745424755261460',
name: 'Acquire Esports',
icon: '3e5813604551b3d2d186c522f590b002',
features: [
'ROLE_ICONS',
'ANIMATED_ICON',
'PRIVATE_THREADS',
'COMMUNITY',
'MEMBER_PROFILES',
'PREVIEW_ENABLED',
'THREE_DAY_THREAD_ARCHIVE',
'SEVEN_DAY_THREAD_ARCHIVE',
'NEWS',
'NEW_THREAD_PERMISSIONS',
'ENABLED_DISCOVERABLE_BEFORE',
'INVITE_SPLASH',
'DISCOVERABLE',
'BANNER',
'THREADS_ENABLED',
'WELCOME_SCREEN_ENABLED'
],
commands: <ref *1> GuildApplicationCommandManager {
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: [Circular *2],
guildId: '867745424755261460',
commandId: null
},
guild: [Circular *2]
},
members: GuildMemberManager { guild: [Circular *2] },
channels: GuildChannelManager { guild: [Circular *2] },
bans: GuildBanManager { guild: [Circular *2] },
roles: RoleManager { guild: [Circular *2] },
presences: PresenceManager {},
voiceStates: VoiceStateManager { guild: [Circular *2] },
stageInstances: StageInstanceManager { guild: [Circular *2] },
invites: GuildInviteManager { guild: [Circular *2] },
scheduledEvents: GuildScheduledEventManager { guild: [Circular *2] },
available: true,
shardId: 0,
splash: null,
banner: '777383a859a1e4fce1df5b88d0c83ff0',
description: 'Acquire Is A Esports Team Striving To Compete Against The Best Of The Best!',
verificationLevel: 'MEDIUM',
vanityURLCode: null,
nsfwLevel: 'DEFAULT',
discoverySplash: '42ddfb9fe290e4188f1efee94c9a5317',
memberCount: 2108,
large: true,
premiumProgressBarEnabled: true,
applicationId: null,
afkTimeout: 300,
afkChannelId: null,
systemChannelId: '867745424755261463',
premiumTier: 'TIER_2',
premiumSubscriptionCount: 12,
explicitContentFilter: 'ALL_MEMBERS',
mfaLevel: 'ELEVATED',
joinedTimestamp: 1645418832841,
defaultMessageNotifications: 'ONLY_MENTIONS',
systemChannelFlags: SystemChannelFlags { bitfield: 5 },
maximumMembers: 500000,
maximumPresences: null,
approximateMemberCount: null,
approximatePresenceCount: null,
vanityURLUses: null,
rulesChannelId: '867759312230809621',
publicUpdatesChannelId: '950055181276557322',
preferredLocale: 'en-US',
ownerId: '774305195521474611',
emojis: GuildEmojiManager { guild: [Circular *2] },
stickers: GuildStickerManager { guild: [Circular *2] }
}```
Ok, idrk the big problem, prob just uncached member, so do const member = await message.guild.members.fetch(message.author.id) then you can check member.roles
Okay, I will try that in a few minutes here and will let you know the outcome. Thank you.
.
C:\Acquire Bot\node_modules\discord.js\src\rest\RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Unknown User
at RequestHandler.execute (C:\Acquire Bot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Acquire Bot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async GuildMemberManager._fetchSingle (C:\Acquire Bot\node_modules\discord.js\src\managers\GuildMemberManager.js:407:18)
at async Client.<anonymous> (C:\Acquire Bot\events\chatfilteringlink.js:3:24) {
method: 'get',
path: '/guilds/867745424755261460/members/933371391439405066',
code: 10013,
httpStatus: 404,
requestData: { json: undefined, files: [] }
}```
@mild pebble New error.
Who is sending that msg?
Me
How weird... that's a different ID.... show your code
module.exports = (client, instance) => {
client.on("messageCreate", async (message) => {
const member = await message.guild.members.fetch(message.author.id)
if (message.partial) await message.fetch()
const channelIDs = new Array('949756928513421312', '867771270166741043', '867773400733581353', '867773627604926464')
const roleIDs = new Array('946458813505077338', '936780720603558021', '867755665819566130')
if(!message.guild) return;
if(channelIDs.includes(message.channel.id)) return;
message.member.roles.cache.forEach(async (role) => {
if(roleIDs.includes(role.id)) return;
})
if(message.content.toLowerCase().includes("https://discord")) return;
if(message.content.toLowerCase().includes("https://")) {
message.channel.send(`${message.author} Links are disabled in this chat. `)
await message.delete();
}
})
}```
Tag suggestion for @pine tundra:
It's good practice to make your bots ignore other bots, including itself. This can be done through a single line of code:
if (<message>.author.bot) return;
<message> being whatever you defined message as.
It's no longer returning the error, but it's still not ignoring the roles and channels I have set for it to ignore.
Well why would you loop through the roles...
Why would I not?
Your logic doesn't make sense
Use if (!member.roles.hasAny(...arrayOfRoleIds)) message.delete();
@pine tundra
should I do the same for the channel?
Leave the channel one