Error with Heroku/Discord.js "Service Unavailable" - javascript

I found a weird error when trying to start my discord bot on heroku. So, earlier I decided to make a command handler for my bot so I can store commands in separate files, but I had several errors in the code. After posting a question here, one member helped me fix every single error that I got, but then I got a very unusual error that I have no idea what it means.
Here's the heroku log:
2020-11-09T15:09:58.846760+00:00 app[worker.1]: (node:4) UnhandledPromiseRejectionWarning: Response: Service Unavailable
2020-11-09T15:09:58.846780+00:00 app[worker.1]: at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:161:15)
2020-11-09T15:09:58.846780+00:00 app[worker.1]: at processTicksAndRejections (internal/process/task_queues.js:97:5)
2020-11-09T15:09:58.846781+00:00 app[worker.1]: at async RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
2020-11-09T15:09:58.847016+00:00 app[worker.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2020-11-09T15:09:58.847172+00:00 app[worker.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Here's the "index.js":
const Discord = require('discord.js');
const { Client, Collection } = require ('discord.js');
const client = new Discord.Client();
const token = 'TOKEN';
const PREFIX = '-';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('ready', () =>{
console.log('This bot is online');
})
client.on('message', message=>{
let args = message.content.substring(PREFIX.length).split(" ")
switch(args[0]){
case 'help':
client.commands.get('help').execute(message, args);
}
})
client.login(token);
And "help.js" within my "commands" folder:
const Discord = require('discord.js');
module.exports = {
name: 'help',
execute(message, args){
const embed = new Discord.MessageEmbed()
.setTitle(':scroll: │ Help List')
.addField("Here is a list of commands:\n\n', '$save [name] ➝ Saves the current server template \n $load [link] ➝ Loads a template via link \n $cc [name] ➝ Creates a channel \n $dc [name] ➝ Deletes a channel \n $config [name]➝ Changes the server's name \n $mod [name] ➝ Adds/Removes the member from the moderator role \n $admin [name] ➝ Adds/Removes someone from the admin list")
message.channel.send(embed)
}
}
I do not understand what this error comes from and it has no additional information. I restarted my dynos several times and also checked the status page of heroku, but everything seems file.
Any ideas on how to fix it?

Discord had a pretty bad incident yesterday, which made it unavailable for most people.
Give it a try again today, it should work normally :)

Related

How can I solve login error on discord.js [duplicate]

This question already has answers here:
Why am I getting a ReferenceError: AbortController is not defined in Discord.js v13?
(3 answers)
Closed 1 year ago.
const {Client, Intents} = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.login(token);
I have this code, every time i try to run it returns me the same error:
(node:13284) UnhandledPromiseRejectionWarning: ReferenceError:
AbortController is not defined
at RequestHandler.execute (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:172:15)
at RequestHandler.execute (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:176:19)
at RequestHandler.push (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\rest\RequestHandler.js:50:25)
at async WebSocketManager.connect (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\client\websocket\WebSocketManager.js:128:9)
at async Client.login (C:\Users\Luis\Vainas\Pruebas\node_modules\discord.js\src\client\Client.js:245:7)
(Use node --trace-warnings ... to show where the warning was
created) (node:13284) UnhandledPromiseRejectionWarning:
Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block, or by rejecting a
promise which was not handled with .catch(). To terminate the node
process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).
(rejection id: 2) (node:13284) [DEP0018] DeprecationWarning: Unhandled
promise rejections are deprecated. In the future, promise rejections
that are not handled will terminate the Node.js process with a
non-zero exit code.
Dont know how to fix it. I tried and investigate on the documentation but cant find the solution.
I've added this line to my code to find the error:
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
Getting this:
{ code: 500, method: 'get', path: '/gateway/bot', requestData:
{ json: undefined, files: [] } }
The AbortController package was introduced in Node.js v16 (?). So you need to upgrade your Node.js version. Discord.js v13 requires you to use Node.js v16 and higher as stated in their documentation.
Depending on your operating system, you can either install 64bits or 32bits version of Node.js. Head over to the official website and download 16.8.x (Current, Latest Features) Windows installer.
After installation, verify the version by typing node -v in your console.

Making a new channel discord.js v11.3

I'm trying to make a ticket bot, but I'm not sure what is wrong with my !new command. Please help. I'm using what discord has in their docs The code is below.
const Discord = require('discord.js');
module.exports.run = async (bot, message, args) => {
message.react('✅');
let modrole = message.guild.roles.cache.find(r => r.name === 'Staff');
if (!modrole) {
console.log('Err: ModRole Not Found');
}
message.reply(`${message.author.username}#${message.author.discriminator}`);
message.guild.createChannel(`${message.author.username}#${message.author.discriminator}`, {
parent: '',
topic: message.author.id,
type: '',
permissionOverwrites: [
{ id: message.guild.id, deny: ['VIEW_CHANNEL'] },
{ id: modrole.id, allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'] },
{ id: message.author.id, allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'] }
]
}).then(c => {
message.reply(`, <#Staff>`)
const embed = new Discord.message.embed()
.setTitle('**New Ticket**')
.setDescription(`Thank you for opening a ticket *<#${message.author.id}>, a staff member will be with you shortly!`)
})
}
//name this whatever the command name is.
module.exports.help = {
name: "new"
}
These are the errors:
(node:1664) UnhandledPromiseRejectionWarning: TypeError: message.guild.createChannel is not a function
at Object.module.exports.run (C:\Users\8fwbu\Desktop\CodeTProj\Molten Dev\commands\new.js:20:19)
at Client.<anonymous> (C:\Users\8fwbu\Desktop\CodeTProj\Molten Dev\main.js:42:31)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\8fwbu\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\8fwbu\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1664) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1664) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Chances are you're not running Discord.js V11. If you installed Discord.js using the following command (Or updated it using the same command)
npm install discord.js
You're working on Discord.js V12. In Discord.js V12, <Guild>.createChannel is not a function. Instead, you'll use <Guild>.channels.create(). If you wish to return to Discord.js V11, you can use this command. This will overwrite the current Discord.js package with the most recent Discord.js V11 update.
npm install discord.js#11
The #11 indicates that you want V11, not V12.
Additionally, I would like to point out that putting a hashtag (#) in the title is not recommended or allowed by Discord. The channel will be created, except the hashtag will be excluded from the channel name which will result in something like this: User#0000 => #user0000. Also keep in mind that certain unicode characters are prohibited from Discord and will not be accepted.

Logging messages from one channel

I've tried several times to work this and I don't understand the error, I am receiving but I'll explain what I'm trying to do: Basically I want to log the messages from one channel and paste those messages onto a different channel. Here is the code I have so far;
client.on(`message`, message => {
if (message.author.bot) return; // If the message is by a bot return.
if (!message.guild) return; // If the message isn't in a guild return.
if (message.guild) {
const msgLog = `[MESSAGE] [${message.guild.name}] [#${message.channel.name}] ${message.author.username}#${message.author.discriminator}: ${message.content}\n` // You can change this to whatever you want.
client.channels.get(`814685640088223795`).send(msgLog); // Replace CHANNEL ID with the channel ID you want the logs to go to.
return;
}
})
The error I am receiving goes as follows:
(node:17260) UnhandledPromiseRejectionWarning: ReferenceError: client is not defined
at Object.<anonymous> (D:\stuff\S1 Discord Bot\s1-bot\src\events\message\message.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at registerEvents (D:\stuff\S1 Discord Bot\s1-bot\src\utils\registry.js:33:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:17260) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:17260) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Thanks
You are missing this from your index file:
const Discord = require("discord.js");
//under const Discord etc
const client = new Discord.Client();
If you are trying to only allow guildMessages, you do it like this:
if (message.channel.type === "dm") return; //dont react to dms
Finally, to send a message to a channel by id:
message.guild.channels.cache.get('814685640088223795').send(msglog); //using 'cache' since v12 uses managers
You seem to be missing two important lines of code:
const Discord = require('discord.js');
const client = new Discord.Client();
Appending these two lines from the discord.js documentation in the beginning of your index.js file should make it work.

Failed to create directory error in Node.js

I'm new to both Node.js and Tensorflow so I apologize if this is kind of stupid. I'm also new to Stack Overflow so I apologize if this isn't the best-formatted question. I'm trying to implement Tensorflow into a Discord bot(to make a chatbot). I have some experience in Java so I was able to fix some node.js errors, but I can't figure out what this error means as it appears to be a Tensorflow error, not a node.js error and I'm completely new to Tensorflow. One more thing: I am using the provided example code found at https://www.tensorflow.org/js/guide/nodejs except for import * as tf from '#tensorflow/tfjs-node' which I replaced with const tf = require('#tensorflow/tfjs-node'); since import gives an error.
The error I am getting:
2020-03-25 21:02:38.317965: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at summary_kernels.cc:57 : Not found: Failed to create a directory: \/tmp; No such file or directory
(node:3504) UnhandledPromiseRejectionWarning: Error: Invalid TF_Status: 5
Message: Failed to create a directory: \/tmp; No such file or directory
at NodeJSKernelBackend.executeMultipleOutputs (C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\nodejs_kernel_backend.js:206:43)
at NodeJSKernelBackend.createSummaryFileWriter (C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\nodejs_kernel_backend.js:1580:14)
at Object.summaryFileWriter (C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\tensorboard.js:98:17)
at TensorBoardCallback.ensureValWriterCreated (C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\callbacks.js:310:40)
at TensorBoardCallback.logMetrics (C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\callbacks.js:296:22)
at TensorBoardCallback.<anonymous> (C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\callbacks.js:262:26)
at step (C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\callbacks.js:61:23)
at Object.next (C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\callbacks.js:42:53)
at C:\Users\BCG04\node_modules\#tensorflow\tfjs-node\dist\callbacks.js:36:71
at new Promise (<anonymous>)
(node:3504) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:3504) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
This is the code with the error:
client.once('ready', () => {
//Start TENSORFLOW tests
const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [200] }));
model.compile({
loss: 'meanSquaredError',
optimizer: 'sgd',
metrics: ['MAE']
});
// Generate some random fake data for demo purpose.
const xs = tf.randomUniform([10000, 200]);
const ys = tf.randomUniform([10000, 1]);
const valXs = tf.randomUniform([1000, 200]);
const valYs = tf.randomUniform([1000, 1]);
// Start model training process.
async function train() {
await model.fit(xs, ys, {
epochs: 100,
validationData: [valXs, valYs],
// Add the tensorBoard callback here.
callbacks: tf.node.tensorBoard('/tmp/fit_logs_1')
});
}
train();
//End TENSORFLOW tests
console.log('Ready!');
console.log("Servers:")
client.guilds.cache.map((guild) => {
console.log(" - " + guild.name)
// List all channels
client.guilds.cache.map((channel) => {
console.log(` -- ${channel.name} (${channel.type}) - ${channel.id}`)
});
});
});
As you are running on windows machine, this directory is invalid.
Please replace this line callbacks: tf.node.tensorBoard('/tmp/fit_logs_1') with this
callbacks: tf.node.tensorBoard('C:\\Users\\BCG04')
It seems you dont have access to create tmp folder on root as indicated on the code tf.node.tensorBoard('/tmp/fit_logs_1'). Try to change the path.
For me i've change it into tf.node.tensorBoard('.tmp/fit_logs_1') so it will create .tmp directory on current working path.

I Got A "UnhandledPromiseRejectionWarning" And A "DeprecationWarning" When Trying To Run The Code For The Bot, Any Solution To Fix This Problem?

Im Trying To Make A Discord Bot For A Server, I Entered "node ." into the terminal to run the bot and i got this error:
(node:17632) UnhandledPromiseRejectionWarning: Error: Incorrect login details were provided.
at WebSocketConnection.<anonymous> (C:\Users\Thela\code\node_modules\discord.js\src\client\ClientManager.js:48:41)
at Object.onceWrapper (events.js:300:26)
at WebSocketConnection.emit (events.js:210:5)
at WebSocketConnection.onClose (C:\Users\Thela\code\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:390:10)
at WebSocket.onClose (C:\Users\Thela\code\node_modules\ws\lib\event-target.js:124:16)
at WebSocket.emit (events.js:210:5)
at WebSocket.emitClose (C:\Users\Thela\code\node_modules\ws\lib\websocket.js:191:10)
at TLSSocket.socketOnClose (C:\Users\Thela\code\node_modules\ws\lib\websocket.js:850:15)
at TLSSocket.emit (events.js:215:7)
at net.js:658:12
(node:17632) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either
by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:17632) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
In The Terminal.
This Is The index.js file:
const Discord = require('discord.js');
const config = require('./config.json');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.content === '!ping') {
message.channel.send('Pong.');
}
});
client.login(config.token);
And Here Is The config.json:
{
"prefix": "!",
"token": "7F2x4ct0AMuBeJKZUGmtIz_RZVKve-N4"
}
i realised i didnt put the full error
oops
What you are using as "token" is actually your client secret, the token should look something like this:
NjQwOTM2MjE3MTg5Mjg1ODg4.XcGSOQ.3dgX4GbvEDZKYHnCb6nJORuvL1w

Categories