#Could not find the requested invite

1 messages · Page 1 of 1 (latest)

tough pike
export default function (message: Message) {
    if (message.content.toLowerCase().includes("discord.gg/")) {
        const inviteLink = message.content.match(/discord.gg\/[a-zA-Z0-9]+/g)
        const inviteCode = inviteLink?.map((link) => link.split("/")[1])

        if (inviteCode) {
            console.log(inviteCode[0])
            message.guild?.invites
                .fetch({ code: inviteCode[0], force: true })
                .then((invite) => {
                    if (!invite.guild) return
                    if (!invite.guild.id) return
                    if (serverWhitelist.includes(invite.guild.id)) return

                    message.delete()
                    console.log(invite)
                })
                .catch((e) => {
                    console.log(e)
                })
        }
    }
}```

Hello, I have this script for detecting invite links sent in chat
Whenever I post an invite, it errors with "Could not find the requested invite"

Can someone please tell me what is wrong?
InviteLink would be an invite link like discord.gg/....
InviteCode is whatever text is after discord.gg/

(must mention that the invitelink and invitecode are both valid and come from a valid invite link)