I'm getting this strange error on adding this sending message with the discord Bot. I was following the Scratch Tutorial & everything went fine except this when I try to send a message on bot active.
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity('You', {type: 'WATCHING'});
var mainChannel = client.channels.get('51549559XXXX')
mainChannel.send("Hello, world!")
});
client.on('message', (received) => {
if (received.author == client.user) {
return
}
received.channel.send("You: " + received.content);
});
client.login('TOKEN');
Result:-
`(node:8480) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Access
at C:\Users\Deepanshu\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
at C:\Users\Deepanshu\node_modules\snekfetch\src\index.js:215:21
at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:8480) 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:8480) [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.
(node:8480) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at C:\Users\Deepanshu\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
at C:\Users\Deepanshu\node_modules\snekfetch\src\index.js:215:21
at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:8480) 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: 4)
I have copied your code and tried it, and it works perfectly fine. So the problem must be with some of your permissions, as shown by the error. Maybe the mainChannel that you're trying to send a message doesn't allow messages to be sent from the bot.
Related
Im having some issues getting the command to wait for the bot to dm the user before it kicks them, ive put in a wait 5 second function but it kicks well before 5 seconds is up Below is my code and error.
its saying 'wait' isnt defined but ive looked here and used one of those, with a slight modification.
also i have another not so important question, how would i make it so whoever runs the !kickme command gets logged into a .txt file or something similar?
Edit: i figured id clarify. Yes im trying to kick the user who sent the !kickme command. its meant to be a completely useless command for people to mess around with. it should send them a dm with the server invite(so they can rejoin) and then kick them.
as of now it isnt sending the dm to them, its just kicking them
const Discord = require('discord.js')
module.exports.run = async (bot, message, args) => {
const user = message.author
const member = message.guild.member(user);
message.author.send(`Here is an invite so you can join back! https://discord.gg/FBXSduget2 `)
const timew = async (bot, message, args) => {
wait(5000);
console.log("Waited 5s");
wait(5000);
console.log("Waited an additional 5s");
};
timew();
if (member) {
member
.kick('User was kicked')
.then(() => {
console.log(`${user.tag} Kicked themself`);
message.channel.send(`${user.tag} kicked themself`)
})
.catch(err => {
message.reply('Unable');
console.error(err);
});
}
}
module.exports.help = {
name: "kickme"
}
(node:13216) UnhandledPromiseRejectionWarning: ReferenceError: wait is not defined
at timew (C:\Users\8fwbu\Desktop\CodeTProj\-Tux V2\commands\kickme.js:12:9)
at Object.module.exports.run (C:\Users\8fwbu\Desktop\CodeTProj\-Tux V2\commands\kickme.js:19:7)
at Client.<anonymous> (C:\Users\8fwbu\Desktop\CodeTProj\-Tux V2\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)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13216) 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:13216) [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.
(node:13216) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send messages to this user
at RequestHandler.execute (C:\Users\8fwbu\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async RequestHandler.push (C:\Users\8fwbu\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
(node:13216) 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)
Unicorn-Barf#9255 Kicked themself
Your error comes from using wait(5000); as this is not defined.
You can use await when sending messages to ensure they are sent.
await message.author.send(`Here is an invite`)
message.member.kick('they kicked themself')
client.on("message", async (message) => { let roles = {
๐ข๐ช๐ก๐๐ฅ: "Owner",
ADMIN: "[ADM]",
Moderador: "[MOD]",
DcMod: "[DC]",
Booster: "[BOOST]",
Usuario: "[USER]"
}
let nombrerol = message.member.roles.cache.size <= 1 ? "Usuario" : message.member.roles.highest.name;
message.member.setNickname(`${roles[nombrerol]} ${message.author.username}`) })
and I get this error
(node:2604) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (E:\Bots\Skyliner[RP] Bots\XD\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (E:\Bots\Skyliner[RP] Bots\XD\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
at async GuildMember.edit (E:\Bots\Skyliner[RP] Bots\XD\node_modules\discord.js\src\structures\GuildMember.js:312:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2604) 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:2604) [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.
Means your bot does not have permissions to update the user's nickname. Try giving the bot those permissions and see what it does.
You'll need the MANAGE_NICKNAMES permission assigned to the bot, as per https://stackoverflow.com/a/49866239/1935718.
So i am trying to make my discord bot add roles to someone that dm-ed it, and i cant seem to make it work
Here is the code:
guild.members.fetch(message.author)
.then(member => {
member.roles.set(['roleID']);
});
This is the error that i get:
(node:5692) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'set' of undefined
at D:\Documents\GitHub\InfinitBotPrototip\index.js:48:24
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:5692) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise w
hich 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_unhand
led_rejections_mode). (rejection id: 1)
(node:5692) [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 e
xit code.
I'm making a discord bot and if I type $join into chat, I want the bot to join the voice channel that I'm in, and play a random sound.
case"join":
message.delete( {timeout: 5000})
const voiceChannel = message.member.voice.channel
if(voiceChannel) {
const connection = await voiceChannel.join()
const soundFile = fs.readFileSync("./sounds/")
const randFiles = soundFile[Math.floor(Math.random() * randFiles.length)]
const dispatcher = connection.play(randFiles)
} else {
message.reply("you need to be in a voice channel!").then(message => message.delete( {timeout: 5000}))
}
break;
I'm getting this error:
(node:13932) UnhandledPromiseRejectionWarning: Error: EISDIR: illegal operation on a directory, read
at Object.readSync (fs.js:524:3)
at tryReadSync (fs.js:349:20)
at Object.readFileSync (fs.js:386:19)
at Client.<anonymous> (C:\Users\PC\Desktop\doge_bot\doge-bot.js:124:38)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:13932) 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:13932) [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.
Have you read the documentation for readFileSync()? The only OS that readFileSync() successfully returns data on a directory path is on FreeBSD.
Instead, what it appears you're trying to do is grab a list of the files at a directory path; for this you could use fs.readdirSync():
const soundFile = fs.readdirSync("./sounds/")
fs.readFileSync("./sounds/") is for reading the contents of a file.
You're probably looking for fs.readdirSync("./sounds/") which gives you an array of files in a directory.
i try to excuteJavaScript in electron
function createTestGmail(username, password){
username = '12344444444444444444444444asdasd44444444'
testGmail = new BrowserWindow({
width: 500,
height:300,
backgroundColor:'#ccc',
title:'Kiแปm tra Gmail',
webPreferences: {
nodeIntegration: true,
nativeWindowOpen: true,
}
});
testGmail.loadURL('https://example.com');
testGmail.webContents.openDevTools();
testGmail.webContents.executeJavaScript(`
console.log(`+username+`)
`)
testGmail.on('closed',()=>{
testGmail = null;
})
}
if username is a number it work correctly, if username is a string, like below, it show error code
(node:3752) UnhandledPromiseRejectionWarning: Error: Script failed to execute, this normally means an error was thrown. Check the renderer console for the error.
at WebFrame.<computed> (C:\Users\Vy\Desktop\toolyoutube\node_modules\electron\dist\resources\electron.asar\renderer\api\web-frame.js:64:33)
at WebFrame.executeJavaScript (C:\Users\Vy\Desktop\toolyoutube\node_modules\electron\dist\resources\electron.asar\common\api\deprecate.js:114:32)
at C:\Users\Vy\Desktop\toolyoutube\node_modules\electron\dist\resources\electron.asar\renderer\web-frame-init.js:11:43
at C:\Users\Vy\Desktop\toolyoutube\node_modules\electron\dist\resources\electron.asar\renderer\ipc-renderer-internal-utils.js:7:40
at new Promise (<anonymous>)
at EventEmitter.<anonymous> (C:\Users\Vy\Desktop\toolyoutube\node_modules\electron\dist\resources\electron.asar\renderer\ipc-renderer-internal-utils.js:7:9)
at EventEmitter.emit (events.js:200:13)
at Object.onMessage (C:\Users\Vy\Desktop\toolyoutube\node_modules\electron\dist\resources\electron.asar\renderer\init.js:42:16)
(node:3752) 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: 1)
(node:3752) 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: 1)
(node:3752) [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.
(node:3752) [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.
i have try with tag and it have the same problem
I saw #Bravo answered your question through a comment, but just to improve it, since you're using a template string, you could just:
testGmail.webContents.executeJavaScript(`console.log('${username}')`)
It's cleaner that way (since this is the main purpose of a template string, not only allowing to have a multiline text) and you avoid doing string concatenation with the "+" operator.
Sometimes you will mess with single quote and quote mark.
I made an util function to log everywhere.
function logEverywhere(mainWindow, message) {
if (mainWindow && mainWindow.webContents) {
mainWindow.webContents.executeJavaScript(`console.log(\`${message}\`)`);
}
}
I was taking a UDEMY course called Master Electron: Desktop Apps with HTML, JavaScript & CSS, by Ray Viljoen
And in Lesson 3.17. Session: DownloadItem, I got this same error:
(node:9552) UnhandledPromiseRejectionWarning: Error: Script failed to execute, this normally means an error was thrown. Check the renderer console for the error.
at WebFrame.e.startsWith.e.startsWith.WebFrame.<computed> [as _executeJavaScript] (electron/js2c/renderer_init.js:87:1542)
at electron/js2c/renderer_init.js:139:429
at electron/js2c/renderer_init.js:123:361
at EventEmitter.<anonymous> (electron/js2c/renderer_init.js:127:872)
at EventEmitter.emit (events.js:223:5)
at Object.onMessage (electron/js2c/renderer_init.js:115:818)
(node:9552) 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: 1)
(node:9552) [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 my case I tracked the bug/problem down to some code that had a divide by zero in the event handler for DownloadItem.on. The code snippet in question is:
ses.on('will-download', (e, downloadItem, webContents) => {
let fileName = downloadItem.getFilename()
let fileSize = downloadItem.getTotalBytes() // this was zero (which caused the bug)
downloadItem.on('updated', (e, state) => {
let received = downloadItem.getReceivedBytes()
if (state === 'progressing' && received) {
// THE NEXT LINE CAUSED the divide by zero exception because fileSize was zero.
let progress = Math.round((received/fileSize)*100)
webContents.executeJavaScript(`window.progress.value = ${progress}`)
}
})
})
So my takeaway is that Electron's stack didn't help me identify where the bug is but the but was a normal coding error. Not having an exception that included a line number of my code made this particularly difficult to debug/isolate.
The underlying problem was caused by the URL being used when the course was written no longer working. From site: https://file-examples.com/.