am quite new to flutter and my code is pretty much a mess but can anyone explain why db. update doesn't work, whenever I try to update it throws this error
"error when trying to update"(https://i.stack.imgur.com/4cCdt.png)
"code"(https://i.stack.imgur.com/yDoIl.png)
"UI" (https://i.stack.imgur.com/HkahR.png)
all that its supposed to do is when the save icon is pressed it takes input from both title and body and saves them as it is shown above, but instead it throws the error when trying to update. can anyone help please ?
this how my update function goes:
Future update(Note note) async {
final db = await instance.database;
final id = await db.update(
tableNotes,
note.toJson(),
where: '${NoteFields.id} = ?',
whereArgs: [note.id]);
return note.copy(id: id);
}
As per your screenshot, the data you are passing is null, that's why it is showing an error, before updating check what data you are sending.
solved it by adding the parameter id which then specifyed what it was adding txt and txt2 to
Related
First I create an object
var queue = {1:{},2:{},3:{}};
And then I store the message based on QueueKey, or edit if it's already created
if (typeof queue[QueueKey].messageOBJ == 'undefined')
{
queue[QueueKey].messageOBJ = await configChannel.send({ embeds: [getEmbedFloor(QueueKey)] });
}
else
{
queue[QueueKey].messageOBJ = await queue[QueueKey].messageOBJ.edit({ embeds: [getEmbedFloor(QueueKey)] });
}
everything starts working well but after sometime(1~2 hours) bot stops editing the already created message, looks like it lose object reference.
It not pops any error message or code break, seems like the message was edited sucessfully but the real message in discord still the same
I'm thinking in store the messageID instead the whole object and search for the message ID with .fetch() but this will lead to other problems
is there any way to store message Objects properly?
I discovered my problem, actually bot was editing the message to frequently, so after some time discord "auto ban" my bot for some time, something like a cooldown, só it starts to get slower and slower, up to seems like it is stuck.
My solution was check message before edit, to compare if the changes in message are really necessary, before edit or not
I'm using Node and Discord.JS, trying to see if there's a way to differentiate between types of edits whenever a message is edited so a bot can tease the user for editing their message. The function works well so far, and is as follows:
let responses = ["some", "responses"];
bot.on('messageUpdate', ( message ) => {
let result = responses[Math.floor(Math.random()*(responses.length)-1)]
message.channel.send(result);
})
However, this detects all message updates, including say a link updating to have an embed. Is there any way to differentiate between a deliberate user edit and a message being updated with an embed through event listeners, or will I need to make a workaround with an if..else statement?
To check when message is edited, You'll be required to use the messageUpdate event listener.
In the messageUpdate event, there is 2 parameters. (oldMessage, newMessage) Learn More
Then, you can check the content of the oldMessage & newMessage parameters by using the .content property.
Example of code:
client.on("messageUpdate", (oldMessage, newMessage) => {
if(oldMessage.content === newMessage.content) return // Will do nothing if the content of oldMessage is equals to newMessage's content
// Do here your stuff
})
I hope I helped you!
Ignore this, i have not found an answer as I had hoped ;(
I have a problem on how to save a DateTime on a data base with sqflite , so even if I change a page the date won't desapear, Could any one help me please ? Thank you .
enter image description here
If you just need to save one date, sqflite is overkill, take a look at shared_preferences.
onPressed: ()async{
final selectedDate= await selectTimePicker(context);
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.seString('date', '$selectedDate');
}
if (message.content === "!test"){
client.users.cache.get('id').send('message');
console.log("message sent")
}
This method doesn't work and I wasn't able to find any other methods that worked
Is there a spelling mistake or this method is outdated?
I've actually encountered this error myself once. There are two problems you might be facing here:
The user isn't cached by discord.js yet
There isn't a DMChannel open for that user yet
To solve the first one, you have to fetch the user before doing anything with it. Remember this is a Promise, so you'll have to either await for it to complete or use .then(...).
const user = await client.users.fetch('id')
Once you've fetched your user by their ID, you can then create a DMChannel which, again, returns a promise.
const dmChannel = await user.createDM()
You can then use your channel like you normally would
dmChannel.send('Hello!')
Try to create a variable like this:
var user = client.users.cache.find(user => user.id === 'USER-ID')
And then do this:
user.send('your message')
ABOUT ME:
This question is aimed at using for a Discord bot using Discord.js
I'm used to doing coding in older coding languages like C++, C#, Batch, and Game Maker Studio, but I'm still new to Discord.js
THE INTENT:
I want to store some basic variables. Such as "Server Rupees" which is shared by everyone.
And maybe a couple others. Nothing individual. Not a database. Not an array.
THE QUESTION:
I've heard this can be done with a json file. How do I save one variable to a place I can get it back when the bot goes online again?
And once I have it saved. How do I get that variable back?
WHAT I KNOW:
Not a lot for Discord.js . My bot has about 20 different commands, like adding roles, recognizing a swear and deleting that message, kick/ban a user, bulk delete messages, etc.
Yes it can be done with a json file or database,
If you are gonna go with json:
Store the value inside of a json file to start of with, for example:
./my-data.json
{ "Server-Rupees": 200 }
You would get the result by requiring the file
const data = require("path-to-json.json");
console.log(data["Server-Rupees"])
// => 200
If you want to update the value, just update the property value and use fs.writeFile
const { writeFile } = require("fs");
const data = require("path-to-json.json");
data["Server-Rupees"] += 20;
//JSON.striginfy makes the object into a string, `null, 6` makes it prettier
writeFile("path-to-json.json", JSON.stringify(data, null, 6), err => {
if(err) console.error(err);
})
Note: writeFile's path won't always be the same as require's path even for the same file.