// Necessary imports for running the discord bot smoothly
import DiscordJS, { TextChannel, Intents, Message, Channel, NewsChannel, ThreadChannel, DiscordAPIError } from 'discord.js'
type guildTextBasedChannel = TextChannel | NewsChannel | ThreadChannel
import dotenv from 'dotenv'
dotenv.config()
// Setting the command prefix for the bot
const prefix = '~';
// Initializing the client with specific intentions for the bot's use
const client = new DiscordJS.Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGES
]
})
// Displays "The bot is ready" message when the bot is turned on
client.on('ready', () => {
console.log('The bot is ready')
})
// Logging in to the bot using the provided token
client.login(process.env.token)
I am currently working on creating a discord bot and aiming to have it operational 24/7 using GitHub and Heroku. However, I encountered an error while trying to run it on Heroku.
I suspect that the error may be due to my usage of TypeScript for the bot. Do I need to convert it to JavaScript or is there a simple solution?
EDIT:
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// Required imports for successful execution of the discord bot
const discord_js_1 = __importStar(require("discord.js"));
const dotenv_1 = __importDefault(require("dotenv"));
dotenv_1.default.config();
// Setting the command prefix for the bot
const prefix = '~';
// Initializing the client with specific intentions for the bot's use
const client = new discord_js_1.default.Client({
intents: [
discord_js_1.Intents.FLAGS.GUILDS,
discord_js_1.Intents.FLAGS.GUILD_MESSAGES,
discord_js_1.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
discord_js_1.Intents.FLAGS.DIRECT_MESSAGES
]
});
// Displays "The bot is ready" message when the bot is turned on
client.on('ready', () => {
console.log('The bot is ready');
});
client.login(process.env.token);
Above is the index.js code after executing "tsc".
The image above shows the error message I received on Heroku.