feat(arabot): add login function

This commit is contained in:
Anthony 2022-07-09 04:07:35 +01:00
parent e6702973d2
commit 26add44bd0
3 changed files with 67 additions and 0 deletions

14
package-lock.json generated
View File

@ -13,6 +13,7 @@
"@sapphire/ts-config": "^3.3.4", "@sapphire/ts-config": "^3.3.4",
"@types/node": "^18.0.3", "@types/node": "^18.0.3",
"discord.js": "^13.8.1", "discord.js": "^13.8.1",
"dotenv": "^16.0.1",
"typescript": "^4.7.4" "typescript": "^4.7.4"
}, },
"devDependencies": { "devDependencies": {
@ -858,6 +859,14 @@
"node": ">=6.0.0" "node": ">=6.0.0"
} }
}, },
"node_modules/dotenv": {
"version": "16.0.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
"integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==",
"engines": {
"node": ">=12"
}
},
"node_modules/es-abstract": { "node_modules/es-abstract": {
"version": "1.20.1", "version": "1.20.1",
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz",
@ -3271,6 +3280,11 @@
"esutils": "^2.0.2" "esutils": "^2.0.2"
} }
}, },
"dotenv": {
"version": "16.0.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
"integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ=="
},
"es-abstract": { "es-abstract": {
"version": "1.20.1", "version": "1.20.1",
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz",

View File

@ -28,6 +28,7 @@
"@sapphire/ts-config": "^3.3.4", "@sapphire/ts-config": "^3.3.4",
"@types/node": "^18.0.3", "@types/node": "^18.0.3",
"discord.js": "^13.8.1", "discord.js": "^13.8.1",
"dotenv": "^16.0.1",
"typescript": "^4.7.4" "typescript": "^4.7.4"
}, },
"devDependencies": { "devDependencies": {

52
src/index.ts Normal file
View File

@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
Animal Rights Advocates Discord Bot
Copyright (C) 2022 Anthony Berg
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
I used the Sapphire documentation and parts of the code from the Sapphire CLI to
create this file.
*/
import { LogLevel, SapphireClient } from '@sapphire/framework';
require('dotenv').config();
// Setting up the Sapphire client
const client = new SapphireClient({
defaultPrefix: process.env.DEFAULT_PREFIX,
logger: {
level: LogLevel.Debug,
},
intents:
['GUILDS',
'GUILD_MESSAGES'],
});
// Main function to log in
const main = async () => {
try {
const token = process.env.DISCORD_TOKEN;
client.logger.info('Logging in');
await client.login(token);
client.logger.info('Logged in');
} catch (error) {
client.logger.fatal(error);
client.destroy();
process.exit(1);
}
};
main();