mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-22 06:31:06 +01:00
feat: add removeExclamationFromNicknames
This commit is contained in:
parent
07fd5bc8a6
commit
eff01b65de
2 changed files with 45 additions and 0 deletions
|
@ -13,9 +13,15 @@ import registerCommands from './utils/registerCommands';
|
|||
import { Option, OptionOptions } from './structures/Option';
|
||||
import { AutocompleteContext } from './structures/contexts/AutocompleteContext';
|
||||
import { deleteIssueOrPR, fetchIssues, fetchPullRequests, setIssue, setPullRequest } from './utils/githubUtils';
|
||||
import { removeExclamationFromNicknames } from './utils/discord';
|
||||
|
||||
await fetchIssues();
|
||||
await fetchPullRequests();
|
||||
(async() => {
|
||||
Logger.info('Removing exclamation marks from nicknames...');
|
||||
await removeExclamationFromNicknames();
|
||||
Logger.info('Removing is done!');
|
||||
})();
|
||||
await loadCommands();
|
||||
try {
|
||||
await registerCommands(config.client.token, config.client.id);
|
||||
|
|
39
src/utils/discord.ts
Normal file
39
src/utils/discord.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
export const getDiscordGuildMembers = async() => {
|
||||
let oldId;
|
||||
const result: any[] = [];
|
||||
|
||||
while (true) {
|
||||
const members: any[] = await (await fetch(
|
||||
`https://discord.com/api/v8/guilds/${process.env.DISCORD_GUILD_ID}/members?limit=1000${oldId ? `&after=${oldId}` : ''}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bot ${process.env.DISCORD_BOT_TOKEN}`,
|
||||
},
|
||||
}
|
||||
)).json();
|
||||
|
||||
if (!members.length) break;
|
||||
|
||||
result.push(...members.map(m => ({ id: m.id, nickname: m.nick })));
|
||||
oldId = members[members.length - 1].id;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export const removeExclamationFromNicknames = async() => {
|
||||
for (const member of await getDiscordGuildMembers()) {
|
||||
if (!member.nickname?.startsWith?.('!')) continue;
|
||||
|
||||
await fetch(`https://discord.com/api/v8/guilds/${process.env.DISCORD_GUILD_ID}/members/${member.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
Authorization: `Bot ${process.env.DISCORD_BOT_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
nick: member.nickname.slice(1),
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue