I'm a discord bot developer and I use an SQLite database for my bot. I installed sqlite3 by npm command and I worked with it, there was no problem, but now I can't use it because it modifies values. I have a bit of code here:
const ghostChannels = await new Promise((resolve, reject) =>
client.db.all(`SELECT * FROM "Ghosts"`, (err, rows) =>
err ? reject(err) : resolve(rows)
)
);
ghostChannels.forEach(async (channel) => {
const guildchannel = await message.member.guild.channels.cache.get(
channel.id
);
console.log(channel.id);
console.log(guildchannel);
const mess = await guildchannel.send(message.member);
await mess.delete();
});
Unfortunately it returns an error:
Uncaught TypeError TypeError: channel.send is not a function
So I looked at the id, and saw that it's not the same ID as in the database:
I don't know how to fix it, so if someone knows, tell me :)
CodePudding user response:
Maybe you do it in a wrong way? calling in any database need some gateway (idk the exact name). for ex:
const ghostChannels = await new Promise((resolve, reject) =>
client.db.all(`SELECT * FROM "Ghosts"`, (err, rows) =>
err ? reject(err) : resolve(rows)
)
);
ghostChannels.forEach(async (channel) => {
const guildchannel = await message.member.guild.channels.cache.get(
channel.id
);
console.log(channel.id);
console.log(guildchannel);
const mess = await channel.send(message.member);
await mess.delete();
});
since you called your guildchannel to db
your:
const mess = await channel.send(message.member);
should be:
const mess = await guildchannel.send(message.member);
EDIT:
I've seen that guildchannel shows as undefined, you can try:
await guildchannel.channel?.send
or something like this:
const chan = message.guild.channels.cache.get(`${channel.id}`)
chan.send("set")
CodePudding user response:
The problem is that you try to store snowflakes as integers (e.g. 988185997772738610), while you should store them as strings ("988185997772738610"). As these IDs are greater than 53 bits (MAX_SAFE_INTEGER), JavaScript has difficulty interpreting them. It can only safely represent integers between -(253 - 1) and 253 - 1.
| Max safe integer | 9007199254740992 |
| Your integer | 988185997772738610 |
| Your integer becomes | 988185997772738600 |
As you can see, every discord ID/snowflake's last two digits become 0 if they're stored as integers. You can even try it below:
console.log(988185997772738610)
// => 988185997772738600
console.log('988185997772738610')
// => "988185997772738610"
So to solve your problem, make sure you insert the channel (and other) IDs as strings into the database.


