i am trying to convert my old discord bot from node js 6.x.x to 8.x.x, i am also putting the commands in a separate folder to make it look cleaner, the command works on my old bot but not with this bot, i get
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'id' of null
UPDATED CODE STILL RETURNS THE SAME:
var settings = '../settingsConfig/settings.json';
var file = require(settings)
const SteamTotp = require('steam-totp');
const Discord = require('discord.js');
const configS = require('../settingsConfig/ConfigSammy.json');
const configJ = require('../settingsConfig/ConfigJack.json');
const configB = require('../settingsConfig/ConfigBen.json');
module.exports.run = async (bot, message, args) => {
function myFunc(){
var JackCode = SteamTotp.getAuthCode(configJ.sharedSecret);
var BenCode = SteamTotp.getAuthCode(configB.sharedSecret);
var SammyCode = SteamTotp.getAuthCode(configS.sharedSecret);
var codess = new Discord.RichEmbed()
.addField("__**Bens Code:**__", BenCode)
.addField("__**Jacks Code:**__", JackCode)
.addField("__**Sammys Code:**__", SammyCode)
.setColor(0x00FF00)
message.author.send(codess)
}
new myFunc();
};
module.exports.help = {
name: "codes"
}
Looks like the error comes from having message.guild not being defined, there for calling message.guild.id yields the error
The reason you're getting this specific error is since you are using the async keyword, which basically means you are using a promise, but you don't provide a reject method for it, hence UnhandledPromiseRejectionWarning
The error may occur because your MongoDB would not be connected. Try to repair it while installing MongoDB.
Related
Does anyone know what's wrong with this code?
await window.solana.connect();
let fromWallet = window.solana.publicKey;
let toWallet = new PublicKey("<KEY>");
let transaction = new Transaction();
transaction.add(
SystemProgram.transfer({
fromPubKey: fromWallet,
toPubKey: toWallet,
lamports: LAMPORTS_PER_SOL
})
);
transaction.feePayer = fromWallet;
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
let bk = await connection.getLatestBlockhash();
transaction.recentBlockhash = bk.blockhash;
const signature = await window.solana.signAndSendTransaction(await transaction);
await connection.confirmTransaction(signature);
console.log(signature);
It throws an error at line
const signature = await window.solana.signAndSendTransaction(await transaction)
Something about converting undefined to base58.
I have checked the keys, they are both fine.
Here is the error log:
vue.runtime.esm.js?2b0e:1897 TypeError: Cannot read properties of undefined (reading 'toBase58')
at eval (index.browser.esm.js?64b9:2451:1)
at Array.sort (<anonymous>)
at Transaction.compileMessage (index.browser.esm.js?64b9:2450:1)
at Transaction._compile (index.browser.esm.js?64b9:2563:1)
at Transaction.serializeMessage (index.browser.esm.js?64b9:2585:1)
at ia (inpage.js:141:130205)
at inpage.js:141:137033
at c (inpage.js:2:47880)
at Generator._invoke (inpage.js:2:47668)
at Generator.next (inpage.js:2:48309)
Any ideas?
Oh dear lord,
I fixed the issue by changing the code:
transaction.add(
SystemProgram.transfer({
fromPubKey: fromWallet,
toPubKey: toWallet,
lamports: LAMPORTS_PER_SOL
})
);
to the following:
const instruction = SystemProgram.transfer({
fromPubkey: fromWallet,
toPubkey: toWallet,
lamports: LAMPORTS_PER_SOL,
});
transaction.add(instruction);
I still don't understand why it works, but hey it solved my issue.
The error TypeError: Cannot read properties of undefined (reading 'toBase58') typically means that there's an invalid PublicKey somewhere.
Assuming that the connection to the wallet is correct, there's probably an issue with the line:
let toWallet = new PublicKey("<KEY>");
First, be sure that the result of that call is correct, by logging it, ie.:
console.log(toWallet.toBase58());
If that works, then there's likely an issue with the wallet connection.
I am encountering a TypeError while trying to set up the commands for my bot.
This happens when trying to use commands.set
function setCommands(): void {
var slashCommandFiles = fs.readdirSync('./commands').filter((file: string) => (file.endsWith('.js') && !forbiddenCommands.includes(file.slice(0, -3))));
for (const file of slashCommandFiles) {
const command = require(`./commands/${file}`);
slashCommands.push(command.data.toJSON());
if (client.application)
client.application.commands.set(command.data.name, command); //happens here
else {
console.error(client);
throw new Error("Unable to load the commands");
}
}
}
The error message is the following:
C:\Overbot\node_modules\discord.js\src\managers\ApplicationCommandManager.js:147
data: commands.map(c => this.constructor.transformCommand(c)),
^
TypeError: commands.map is not a function
at ApplicationCommandManager.set (C:\Overbot\node_modules\discord.js\src\managers\ApplicationCommandManager.js:147:22)
at setCommands (C:\Overbot\index.js:68:41)
at C:\Overbot\index.js:108:17
at step (C:\Overbot\index.js:34:23)
at Object.next (C:\Overbot\index.js:15:53)
at C:\Overbot\index.js:9:71
at new Promise (<anonymous>)
at __awaiter (C:\Overbot\index.js:5:12)
at Client.<anonymous> (C:\Overbot\index.js:98:43)
at Object.onceWrapper (node:events:514:26)
Thing is, it's definitely a function that does exist, since I verified the code and found it with no problem.
I don't think this is a semicolon shenanigan either, because I already tested it with and without semicolons everywhere, to the same result.
Is there any way I can make this work ?
That's not how you set the commands. Use this instead:
client.application.commands.set(slashCommands)
//I assume slashCommands is an array of ApplicationCommandData, according to your code
I'm started to learn discord.js library and trying to make event when user joins special voice channel and bot creates a new one and moves user. Now bot can create channel, but when it tries to move user it have an error "Cannot read properties of undefined (reading 'setChannel')"
Here is my code:
const {Collection} = require('discord.js')
let privateVoice = new Collection()
config = require('../config.json');
module.exports = async (bot, oldState, newState)=>{
const user = await bot.users.fetch(newState.id)
const member = newState.guild.members.fetch(user)
if(!oldState.channel && newState.channel.id === (config.createChannel)){
const channel = await newState.guild.channels.create(user.tag,{
type: "GUILD_VOICE",
parent: newState.channel.parent
})
member.voice.setChannel(channel);
privateVoice.set(user.id, channel.id)
}
};
You are trying to fetch a member by their user object and you aren't even awaiting it. .fetch is a Promise and you use their ID, not their user object.
Instead of using this to get their member object:
const member = newState.guild.members.fetch(user)
Use VoiceState.member
const { member } = newState //object destructuring for cleaner syntax. 'const member = newState.member' is also fine
But this can be null since it gets them from the member cache (see here). If you really want to fetch them, make sure to await it and use their ID
const member = await newState.guild.members.fetch(user.id)
below there is a code hope someone helps me :)
i tried to search on google but didnt find any solutions
const { MessageEmbed } = require("discord.js");
module.exports.run = async (bot, message, args) => {
const snipes = bot.snipes.get(message.channel.id) || [];
const msg = snipes[args[0] - 1 || 0];
if (!msg) return message.channel.send(`That is not a valid snipe...`);
const Embed = new MessageEmbed()
.setAuthor(
msg.author.tag,
msg.author.displayAvatarURL({ dynamic: true, size: 256 })
)
.setDescription(msg.content)
.setFooter(`Date: ${msg.date} | ${args[0] || 1}/${snipes.length}`);
if (msg.attachment) Embed.setImage(msg.attachment);
message.channel.send(Embed);
},
module.exports.help = {
name: "snipe",
}
it is normal for you to attach the error's location (usually in the form error: 53,23 so users can find it more easily.
First of all, undefined errors are the most common errors you will get (please read). They occur when you either havent declared a variable, or a method you have used is incorrect. In this case, I believe it is coming from this line:
const snipes = bot.snipes.get(message.channel.id) || [];
I don't know what snipes is but in v12 we use cache, and #get is out of use as per (also read)
If I knew what snipes was I could tell you what the right code is, but I do not. Please use the info attached to see if you can solve the issue.
I'm working on a game using spark ar, by following the tutorial from youtube (blinking game tutorial).
apparently when I was working there was an error in the script
const Scene = require('Scene');
export const Diagnostics = require('Diagnostics');
const Patches = require("Patches");
Promise.all([
Scene.root.findFirst('number'),]).then(onReady);
function onReady(assets) {
var counterNumber = assets[0];
var scoreNumber = p.outputs.getScalar("score");
scoreNumber.then(e => {
e.monitor().subscribe(value => {
counterNumber.text = value.newValue.toString();
});
});
}
Error : Possible Unhandled Promise Rejection: ReferenceError: Property 'p' doesn't exist
create a const P as below and check whether its working or not
const Scene = require('Scene');
const P = require('Patches');
reference taken from Score Didnt show up (Spark AR)
the problem is on this line :
var scoreNumber = p.outputs.getScalar("score");
"p" is not defined anywhere in your entire code that's why it is throwing error