fix: use token from config

This commit is contained in:
xHyroM 2022-10-20 12:45:22 +02:00
parent 04d462ebb1
commit 14b0c6d252
2 changed files with 6 additions and 6 deletions

View file

@ -19,7 +19,7 @@ await fetchIssues();
await fetchPullRequests(); await fetchPullRequests();
(async() => { (async() => {
Logger.info('Removing exclamation marks from nicknames...'); Logger.info('Removing exclamation marks from nicknames...');
await removeExclamationFromNicknames(); await removeExclamationFromNicknames(config.client.token);
Logger.info('Removing is done!'); Logger.info('Removing is done!');
})(); })();
await loadCommands(); await loadCommands();

View file

@ -1,6 +1,6 @@
import { Logger } from "./Logger"; import { Logger } from "./Logger";
export const getDiscordGuildMembers = async() => { export const getDiscordGuildMembers = async(token: string) => {
let oldId; let oldId;
const result: any[] = []; const result: any[] = [];
@ -9,7 +9,7 @@ export const getDiscordGuildMembers = async() => {
`https://discord.com/api/v8/guilds/${process.env.DISCORD_GUILD_ID}/members?limit=1000${oldId ? `&after=${oldId}` : ''}`, `https://discord.com/api/v8/guilds/${process.env.DISCORD_GUILD_ID}/members?limit=1000${oldId ? `&after=${oldId}` : ''}`,
{ {
headers: { headers: {
Authorization: `Bot ${process.env.DISCORD_BOT_TOKEN}`, Authorization: `Bot ${token}`,
}, },
} }
)).json(); )).json();
@ -27,14 +27,14 @@ export const getDiscordGuildMembers = async() => {
return result; return result;
} }
export const removeExclamationFromNicknames = async() => { export const removeExclamationFromNicknames = async(token: string) => {
for (const member of await getDiscordGuildMembers()) { for (const member of await getDiscordGuildMembers(token)) {
if (!member.nickname?.startsWith?.('!')) continue; if (!member.nickname?.startsWith?.('!')) continue;
await fetch(`https://discord.com/api/v8/guilds/${process.env.DISCORD_GUILD_ID}/members/${member.id}`, { await fetch(`https://discord.com/api/v8/guilds/${process.env.DISCORD_GUILD_ID}/members/${member.id}`, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
Authorization: `Bot ${process.env.DISCORD_BOT_TOKEN}`, Authorization: `Bot ${token}`,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ body: JSON.stringify({