0

I'm trying to write an announce command which when used sends an announcement to the announcements channel, but only if you have a certain role, that works, but it shows an error in my console. The error is TypeError: client.fetchGuild is not a function

if (await client.fetchGuild(message.guild.id).fetchMember(message.author.id).hasPermission("MENTION_EVERYONE") && message.content.startsWith(adminPrefix + 'announce')) {
  const trueMessage = message.content.substr(10)
  client.channels.get('545343689216491541').send('@everyone, ' + trueMessage)
}

How do I make it send no errors

P.s. I'm new to this, very new.

Foccs
  • 3
  • 4

2 Answers2

0
fetchGuild

is not a function. Use

client.guilds.get(id)

or

message.guild

as you already have the guild attached to the message object

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get

https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=guilds

Community
  • 1
  • 1
Saddy
  • 1,515
  • 1
  • 9
  • 20
0

In order to verify if a member has a role, you'd better use this: if(message.member.roles.cache.some(role => role.name === 'role name')) then send the message inside the if statement

imaneeh
  • 26
  • 4