I’m trying to allow staff to reply to the last DM using ~reply <message>
rather than ~dm <userID> <message>
, but firstly, I have to save the user’s ID in a database to know who was the last DM user, but I’m facing an ERROR here, I’m confused of why this may be happening, but please note, I’m really new to databases, I’d apricate some help!
My code (Not all, just what I’m using for the command.):
I added “>>” before the line the ERROR is.
client.on('message', async message => {
//Dm checker
if (message.channel.type === 'dm') {
>> let lastDM = await db.get(`dm_${message.author.id}`)
if (lastDM === null) lastDm = `dm_NONE`
if (message.author.id == client.user.id) return;
if (message.author.id == '818749579369512978') return message.channel.send("This chat has been Blacklisted by the developer (<@"+ BOT_OWNER +">)");
const embed1 = new MessageEmbed()
.setTitle("New message!")
.setAuthor(`Name: `${message.author.username}` ID: `${message.author.id}` `)
.setColor("GRAY")
.setFooter("Dm message")
.addField("Message:", ````${message.content}````, false);
const embed2 = new MessageEmbed()
.setTitle("New reply!")
.setAuthor(`Name: `${message.author.username}` ID: `${message.author.id}` `)
.setColor("GRAY")
.setFooter("Dm reply")
.addField("Reply:", ````${message.content}````, false);
if (lastDM === `dm_${message.author.id}`) {
client.channels.cache.get("920895881656532992").send(`You got a reply!`, embed2)
console.log(lastDM)
} else {
await db.set(`dm_${message.author.id}`).then(
client.channels.cache.get("920895881656532992").send(`I was DMed!`, embed1),
console.log(lastDM)
)
}
}
The ERROR:
(node:703) UnhandledPromiseRejectionWarning: SyntaxError: Failed to parse value of dm_612110791683866644, try passing a raw option to get the raw value
at /home/runner/DwaCraft-Main-bot-Fixed/node_modules/@replit/database/index.js:36:17
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Client.get (/home/runner/DwaCraft-Main-bot-Fixed/node_modules/@replit/database/index.js:20:12)
at async Client.<anonymous> (/home/runner/DwaCraft-Main-bot-Fixed/main.js:116:18)
(node:703) 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)