mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-06-07 23:49:29 +00:00
Completely nuked everything - starting over from scratch :)
This commit is contained in:
parent
7357cce1d4
commit
169ef72bfd
11 changed files with 19 additions and 492 deletions
|
@ -1,78 +1,17 @@
|
|||
import * as config from "./discord-bot/config";
|
||||
import * as l_config from "./config";
|
||||
import * as l_discord from "./discord";
|
||||
import * as l_util from "./util";
|
||||
import * as c_discord_bot from "../config/discord-bot";
|
||||
// Require the necessary discord.js classes
|
||||
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
||||
import config from '../config.json' assert { type: 'json' };
|
||||
|
||||
export class DiscordBot extends l_discord.Bot {
|
||||
public static config: l_config.Config<config.Config_Interface>;
|
||||
public static discord_bot: l_discord.Bot;
|
||||
public static polling_interval: 50; // ms
|
||||
public static guild: l_discord.Guild;
|
||||
|
||||
static main(
|
||||
p_config: config.Config_Interface
|
||||
) {
|
||||
console.log("Running bot tasks")
|
||||
const { token } = config;
|
||||
|
||||
console.log("-- Loading configuration");
|
||||
this.config = new l_config.Config(
|
||||
config.defaulted,
|
||||
p_config
|
||||
);
|
||||
// Create a new client instance
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
this.discord_bot = new l_discord.Bot(this.config.real.discord);
|
||||
// When the client is ready, run this code (only once)
|
||||
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
|
||||
client.once(Events.ClientReady, c => {
|
||||
console.log(`Ready! Logged in as ${c.user.tag}`);
|
||||
});
|
||||
|
||||
try {
|
||||
console.log("-- Logging into bot API");
|
||||
this.discord_bot.running = true;
|
||||
} catch (error: any) {
|
||||
DiscordBot.error_stop(error);
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("-- Fetching guild");
|
||||
this.guild = this.discord_bot.get_guild({
|
||||
id: this.config.real.discord.guild_id
|
||||
})[0];
|
||||
} catch (error: any) {
|
||||
DiscordBot.error_stop(error);
|
||||
}
|
||||
|
||||
try {
|
||||
const channel_id = "1043280866744488067";
|
||||
console.log("-- Fetching test channel");
|
||||
|
||||
const channel = this.guild.get_channel({
|
||||
id: channel_id
|
||||
})[0];
|
||||
|
||||
console.log(channel, this.guild);
|
||||
const msg = new l_discord.Message();
|
||||
msg.text = "HELLO TEXT";
|
||||
|
||||
const message_stream = channel.messages;
|
||||
|
||||
const embed = new l_discord.Embed();
|
||||
embed.title = "Hello";
|
||||
embed.description = "IDK";
|
||||
msg.embeds = [ embed ];
|
||||
|
||||
message_stream.push(msg);
|
||||
} catch (error: any) {
|
||||
DiscordBot.error_stop(error);
|
||||
}
|
||||
|
||||
|
||||
console.log("All tasks completed");
|
||||
}
|
||||
|
||||
static error_stop(error: Error) {
|
||||
console.error("Fatal Error: Failed to execute bot tasks");
|
||||
console.error(error);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
DiscordBot.main(c_discord_bot.data);
|
||||
// Log in to Discord with your client's token
|
||||
client.login(token);
|
Loading…
Add table
Add a link
Reference in a new issue