Skip to content

Commit

Permalink
fix(discord): add Discord.ClientOptions (#2714)
Browse files Browse the repository at this point in the history
Added missing gateway intents (as required in v13)

Otherwise, a "TypeError [CLIENT_MISSING_INTENTS]" is thrown due to the upgraded to discord.js v13 in f14a1ca.
For more informations visist discordjs.guide/additional-info/changes-in-v13.html#intents.
  • Loading branch information
Chris-GW committed Aug 13, 2021
1 parent 00b468a commit 3787c54
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/messaging/discord.ts
Expand Up @@ -7,6 +7,9 @@ import {RawUserData} from 'discord.js/typings/rawDataTypes';

const {notifyGroup, webhooks, notifyGroupSeries} = config.notifications.discord;
const {pollInterval, responseTimeout, token, userId} = config.captchaHandler;
const clientOptions: Discord.ClientOptions = {
intents: new Discord.Intents(),
};

function getIdAndToken(webhook: string) {
const match = /.*\/webhooks\/(\d+)\/(.+)/.exec(webhook);
Expand Down Expand Up @@ -66,13 +69,13 @@ export function sendDiscordMessage(link: Link, store: Store) {
const promises = [];
for (const webhook of webhooks) {
const {id, token} = getIdAndToken(webhook);
const client = new Discord.WebhookClient({id, token});
const client = new Discord.WebhookClient({id, token}, clientOptions);

promises.push(
new Promise((resolve, reject) => {
client
.send({
content: notifyText.join(' '),
content: notifyText.length ? notifyText.join(' ') : null,
embeds: [embed],
username: 'streetmerchant',
})
Expand Down Expand Up @@ -199,7 +202,7 @@ export async function sendDMAndGetResponseAsync(
async function getDiscordClientAsync() {
let clientInstance = undefined;
if (token) {
clientInstance = new Discord.Client({} as Discord.ClientOptions);
clientInstance = new Discord.Client(clientOptions);
await clientInstance.login(token);
}
return clientInstance;
Expand Down

0 comments on commit 3787c54

Please sign in to comment.