Discord.js missing access permision what should do? - javascript

I've my own bot but last 2 days I got this error I don't know why? Maybe some command but my bot only can send message and embed message that's why not more permission i don't think so it needed.
Or how can I show which permission is needed?
/home/runner/TruthOrDarejs/node_modules/discord.js/src/rest/RequestHandler.js:349
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/runner/TruthOrDarejs/node_modules/discord.js/src/rest/RequestHandler.js:349:13)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/runner/TruthOrDarejs/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
at async MessageManager.react (/home/runner/TruthOrDarejs/node_modules/discord.js/src/managers/MessageManager.js:193:5)
at async Message.react (/home/runner/TruthOrDarejs/node_modules/discord.js/src/structures/Message.js:720:5) {
method: 'put',
path: '/channels/855192585206366221/messages/919613273811333160/reactions/%E2%9C%85/#me',
 npm start
> TruthOrDarejs#1.0.0 start /home/runner/TruthOrDarejs
> node .
Server is ready.
DB connection sucessfull
Truth Or Dare#7260 Has logged in
/home/runner/TruthOrDarejs/node_modules/discord.js/src/rest/RequestHandler.js:349
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/runner/TruthOrDarejs/node_modules/discord.js/src/rest/RequestHandler.js:349:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/runner/TruthOrDarejs/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
at async GuildInviteManager.create (/home/runner/TruthOrDarejs/node_modules/discord.js/src/managers/GuildInviteManager.js:185:20)
at async Client.<anonymous> (/home/runner/TruthOrDarejs/index.js:298:20) {
method: 'post',
path: '/channels/913210496147132479/invites',
code: 50013,
httpStatus: 403,
requestData: {
json: {
temporary: false,
max_age: 0,
max_uses: 0,
unique: undefined,
target_user_id: null,
target_application_id: undefined,
target_type: undefined
},
files: []
}
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! TruthOrDarejs#1.0.0 start: `node .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the TruthOrDarejs#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-12-12T16_48_03_527Z-debug.log
I added some new permission in the dev portal. but still it gets the error :(

Related

How do I catch an ECONNRESET error using the basic FTP-Library?

I want my program to continue running after catching ECONNRESET. How do I do that? I'm using basic-ftp for my ftp library. Here's the error below:
Node.js v17.7.2
node:events:505
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:164:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
How do I catch it and have the program continue running? I've already tried try/catch blocks shown below:
async connect(port,ip_address){
try{
await this.client.access({
port: port,
host: ip_address,
secure: false
})
}
catch{
this.num_of_files_read=0;
this.files_completed=0;
return 1
}
return 0
}

File writing permissions blocked by the EPERM - Deleting then writing a new file. Node.js

I have a file system function which deletes a file then creates a new one with all new data, I am looking for a possible fix for an error that occurs randomly, and not every time, but around every other time. Here is my current code:
try {
if(fs.existsSync(file)) {
fs.unlink(file, function (err) {});
}
} catch (error){
console.log('There was no file to be deleted');
}
fs.open(file, 'w', function (err, file) {
if (err) throw err;
});
var logger = fs.createWriteStream(file, {
flags: 'a' // 'a' means appending (old data will be preserved)
});
which throws the error occasionally:
C:\Users\codel\OneDrive\Documents\BattlEye\index.js:265
if (err) throw err;
^
Error: EPERM: operation not permitted, open 'C:\Users\codel\OneDrive\Documents\BattlEye\files\610636905440215071.txt'
Emitted 'error' event on WriteStream instance at:
at internal/fs/streams.js:375:14
at FSReqCallback.oncomplete (fs.js:171:23) {
errno: -4048,
code: 'EPERM',
syscall: 'open',
path: 'C:\\Users\\codel\\OneDrive\\Documents\\BattlEye\\files\\610636905440215071.txt'
}
First thing that is noticeable is that this is a cloud drive(OneDrive). With my lack of knowledge about permissions, I decided to test out if the problem was in the OneDrive by transferrring the file to my harddrive. The results were not surprising. It didn't change a thing.
C:\Users\codel\Documents\BattlEye\index.js:265
if (err) throw err;
^
[Error: EPERM: operation not permitted, open 'C:\Users\codel\Documents\BattlEye\files\610636905440215071.txt'] {
errno: -4048,
code: 'EPERM',
syscall: 'open',
path: 'C:\\Users\\codel\\Documents\\BattlEye\\files\\610636905440215071.txt'
}
But the Emmitted 'error' event on WriteStream disappeared from the error log.
Any ideas on why this error is happening and how to fix it?
It looks like you're using asychronous fs calls. Async calls do not work like that.
You can do a search for NodeJS asynchronous programming.

Why is this POST method not inserting data in my Postgres database in Node?

EDIT: This is the error I recieved:
C:\Users\przyb\Desktop\lister\puupy\server.js:33
if (err) throw err;
^
error: missing FROM-clause entry for table "body"
at Parser.parseErrorMessage (C:\Users\przyb\Desktop\lister\puupy\node_modules\pg-protocol\dist\parser.js:241:15)
at Parser.handlePacket (C:\Users\przyb\Desktop\lister\puupy\node_modules\pg-protocol\dist\parser.js:89:29)
at Parser.parse (C:\Users\przyb\Desktop\lister\puupy\node_modules\pg-protocol\dist\parser.js:41:38)
at Socket.stream.on (C:\Users\przyb\Desktop\lister\puupy\node_modules\pg-protocol\dist\index.js:8:42)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puupy#1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the puupy#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\przyb\AppData\Roaming\npm-cache\_logs\2020-07-19T01_30_59_800Z-debug.log
I am trying to insert data into a table in my postgres database using an HTML form and Node for server side. Here is the form:
<form action="/" method="POST">
<input id="Name" type="text" max="100" value="Doggy" name="name">
<input id="query" type="submit" value="Submit">
Code to connect to db:
const Pool = require("pg").Pool;
const pool = new Pool({
user:"postgres",
host:"localhost",
database:"puppy",
password:"Bolek_3003",
port:5432
});
And this is how I am trying to actually insert the data:
var bodyParser = require("body-parser");
var urlencodedParser = bodyParser.urlencoded({extended: false});
app.post('/', urlencodedParser, function(req,res,next){
pool.query("INSERT INTO Users VALUES(null, req.body.name)",(err,res)=>{
if (err) throw err;
console.log(err,res)
});
pool.end()
});
I don't know for how this data to actually be accepted into the database, thanks in advance.
I think there is a mistake in how the request is formatted
const query = {
text: 'INSERT INTO Users(column1, column2) VALUES($1, $2)',
values: [null, `${req.body,name}`],
}
pool.query(query,(err,res)=>{...//})
or this
const query = 'INSERT INTO Users(column1, column2) VALUES($1, $2)',
values= [null, `${req.body,name}`]
}
pool.query(query,values,(err,res)=>{...//})

Heroku: Javascript/MySQL project crashing on request

I have a Heroku API written in JavaScript that reads data from a MySQL database. It previously worked, but now every time I send a request to the API, I get this error:
2020-06-17T18:37:13.493711+00:00 app[web.1]: > my_api#0.0.0 start /app
2020-06-17T18:37:13.493712+00:00 app[web.1]: > node ./bin/www
2020-06-17T18:37:13.493712+00:00 app[web.1]:
2020-06-17T18:37:14.977800+00:00 heroku[web.1]: State changed from starting to up
2020-06-17T18:38:40.255982+00:00 app[web.1]: /app/node_modules/mysql2/lib/connection.js:149
2020-06-17T18:38:40.256022+00:00 app[web.1]: err.fatal = true;
2020-06-17T18:38:40.256023+00:00 app[web.1]: ^
2020-06-17T18:38:40.256023+00:00 app[web.1]:
2020-06-17T18:38:40.256026+00:00 app[web.1]: TypeError: Cannot create property 'fatal' on string 'SOCKS: Authentication failed'
2020-06-17T18:38:40.256027+00:00 app[web.1]: at Connection._handleFatalError (/app/node_modules/mysql2/lib/connection.js:149:15)
2020-06-17T18:38:40.256027+00:00 app[web.1]: at Connection._handleNetworkError (/app/node_modules/mysql2/lib/connection.js:169:10)
2020-06-17T18:38:40.256027+00:00 app[web.1]: at SocksConnection.emit (events.js:315:20)
2020-06-17T18:38:40.256029+00:00 app[web.1]: at /app/node_modules/socksjs/socks.js:146:18
2020-06-17T18:38:40.256029+00:00 app[web.1]: at Socket.dataReady (/app/node_modules/socksjs/socks.js:93:13)
2020-06-17T18:38:40.256029+00:00 app[web.1]: at Socket.emit (events.js:315:20)
2020-06-17T18:38:40.256030+00:00 app[web.1]: at emitReadable_ (_stream_readable.js:556:12)
2020-06-17T18:38:40.256030+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:83:21)
2020-06-17T18:38:40.263200+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-17T18:38:40.263391+00:00 app[web.1]: npm ERR! errno 1
2020-06-17T18:38:40.264251+00:00 app[web.1]: npm ERR! my_api#0.0.0 start: `node ./bin/www`
2020-06-17T18:38:40.264354+00:00 app[web.1]: npm ERR! Exit status 1
2020-06-17T18:38:40.264471+00:00 app[web.1]: npm ERR!
The code in question looks like this:
function new_db_connection() {
var sockConn = new SocksConnection(remote_options, sock_options);
var dbConnection = mysql.createConnection({
user: 'myusername',
database: 'mydatabase',
password: 'mypassword',
stream: sockConn
});
return [sockConn, dbConnection];
};
router.get('/myrequest', function(req, res, next) {
new_conn = new_db_connection();
dbConnection = new_conn[1];
sockConn = new_conn[0];
dbConnection.query('SELECT * from mytable', function(error, results, fields) {
if (error) {
res.send(JSON.stringify({
"status": 500,
"error": error,
"response": null
}));
//If there is error, we send the error in the error section with 500 status
} else {
res.send(JSON.stringify({
"status": 200,
"error": null,
"response": results
}));
//If there is no error, all is good and response is 200OK.
}
sockConn.dispose();
});
dbConnection.end()
});
I saw a similar question asked on here and the solution was to close the connection, but I do close the connection after each request, so I don't know where the issue is.
All help appreciated.
Try to change this
sockConn.dispose();
});
dbConnection.end()
});
in this
sockConn.dispose();
dbConnection.end()
});
});
Edit: reading better the error, it could be the problem is some where else.
Looking at the string 'SOCKS: Authentication failed', could it be that you or the SocksConnection remote endpoint changed something in the authentication?
Hope this helps.
You should take a look at the answer provided by #daniele Rici you need to end your connection properly; however, fixing this will not solve your initial question.
The issue is not with your code. Your issue is with connection configuration.
'fatal' on string 'SOCKS: Authentication failed'
Means there was an error with authentication.
var sockConn = new SocksConnection(remote_options, sock_options);
under the assumention you are using ther npm package socksjs from https://openbase.io/js/socksjs
It is documented that the correct way to initialize a sockjs connection is by doing the following:
var sock = new SocksConnection(remote_options, sock_options);
var sock = SocksConnection.connect(remote_options, sock_options, connect_handler);

Node.js - events.js throw er

Before posting this question I went through a couple of SO posts with the same heading. All of them suggested me to restart my app..I tried that but I am still getting the error.
The code that is throwing the error is
app.post('/insert', function(request, response) {
var connection = mySequel.createConnection(ConnectionParams);
connection.connect();
var UserName = request.body.UserName;
// insert into userrecords values ("123456",DEFAULT,DEFAULT,DEFAULT,10);
var InsertQuery = "insert into userrecords values (" + UserName + ",DEFAULT,DEFAULT,DEFAULT,-10);";
connection.query(InsertQuery, function(error, result, fields) {
if (error) {
response.send("error");
console.log(error);
throw error;
} else {
// response.send("success");
console.log(result.insertId);
response.send(result.insertId);
}
});
connection.end();
});
The error caused by the code is this
events.js:160
2017-04-26T11:42:52.410094+00:00 app[web.1]:
2017-04-26T11:42:52.410092+00:00 app[web.1]: throw er; // Unhandled 'error' event
2017-04-26T11:42:52.410096+00:00 app[web.1]: Error: Quit inactivity timeout
2017-04-26T11:42:52.410097+00:00 app[web.1]: at Quit.<anonymous> (/app/node_modules/mysql/lib/protocol/Protocol.js:160:17)
2017-04-26T11:42:52.410093+00:00 app[web.1]: ^
2017-04-26T11:42:52.410098+00:00 app[web.1]: at emitNone (events.js:86:13)
2017-04-26T11:42:52.410099+00:00 app[web.1]: at Quit._onTimeout (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:127:8)
2017-04-26T11:42:52.410099+00:00 app[web.1]: at Quit.emit (events.js:185:7)
2017-04-26T11:42:52.410100+00:00 app[web.1]: at ontimeout (timers.js:380:14)
2017-04-26T11:42:52.410101+00:00 app[web.1]: at tryOnTimeout (timers.js:244:5)
2017-04-26T11:42:52.410102+00:00 app[web.1]: at Timer.listOnTimeout (timers.js:214:5)
I am hosting my app on Heroku and whenever I try to access this URL the app is crashing forcing me to restart the dyno. The data I am sending is being successfully inserted into the DB but the auto incremented primary key is not being returned to my app. Instead I get a server error.
JSON.stringify() returns the correct value once and after that the app crashed which maked the subsequent requests to fail.
How can I solve this problem?
Try converting your response into JSON before sending it.
Like
response.send(JSON.stringify(result.insertId));
I too once had a similar problem and I think that is how I solved it.
EDIT:
I went through the myql npm library and found something called Pool. Pool is used when you app needs to handle more than one request at a time. I suggest that you try that. There is a good example availble here.
I have same problem, i just downgrade to react-scripts#2.1.8
this is the steps:
cd my-app
npm install react-scripts#2.1.8
npm start

Categories

Resources