-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e9f85b
commit f0a2274
Showing
1 changed file
with
0 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +0,0 @@ | ||
import { GatewayIntentBits, type ClientOptions } from "discord.js"; | ||
|
||
export const { DISCORD_APPLICATION_ID, DISCORD_PUBLIC_KEY, DISCORD_TOKENS } = ( | ||
await import("@Variable/Environment.js") | ||
).default.parse(process.env); | ||
|
||
export const Tokens = | ||
DISCORD_TOKENS.indexOf(",") !== -1 | ||
? DISCORD_TOKENS.split(",") | ||
: [DISCORD_TOKENS]; | ||
|
||
export type Client = { | ||
events?: Map<string, (...args: string[]) => Promise<void>>; | ||
options?: ClientOptions; | ||
token?: string; | ||
preflight?: (...args: string[]) => Promise<void>; | ||
}; | ||
|
||
export type Flight = { | ||
routes: []; | ||
preflight: () => Promise<void>; | ||
}; | ||
|
||
export const Clients: Client[] = [ | ||
{ | ||
token: "", | ||
events: new Map([ | ||
[ | ||
"message", | ||
async (message: string) => { | ||
console.log(message); | ||
}, | ||
], | ||
]), | ||
options: { | ||
intents: [ | ||
GatewayIntentBits.GuildMembers, | ||
GatewayIntentBits.GuildMessages, | ||
GatewayIntentBits.Guilds, | ||
GatewayIntentBits.MessageContent, | ||
], | ||
}, | ||
preflight: async (token: string) => { | ||
const applicationId = DISCORD_APPLICATION_ID; | ||
|
||
if (!DISCORD_PUBLIC_KEY) { | ||
throw new Error( | ||
"The DISCORD_TOKEN environment variable is required.", | ||
); | ||
} | ||
|
||
async function registerCommands(url: string) { | ||
const response = await fetch(url, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bot ${token}`, | ||
}, | ||
method: "PUT", | ||
body: JSON.stringify([AWW_COMMAND, INVITE_COMMAND]), | ||
}); | ||
|
||
if (response.ok) { | ||
console.log("Registered all commands"); | ||
} else { | ||
console.error("Error registering commands"); | ||
|
||
const text = await response.text(); | ||
console.error(text); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
async function registerGlobalCommands() { | ||
await registerCommands( | ||
`https://discord.com/api/v10/applications/${applicationId}/commands`, | ||
); | ||
} | ||
|
||
await registerGlobalCommands(); | ||
}, | ||
}, | ||
]; | ||
|
||
export default Clients.map((Client, Index) => { | ||
const Token = Tokens[Index]; | ||
|
||
if (Token) { | ||
Client.token = Token; | ||
} else { | ||
console.log(`No token for client: ${Index}`); | ||
} | ||
|
||
return Client; | ||
}); | ||