Why are there no Definitions for "LogLevel" and "UseInternalLoghandler"? - dsharp+

i need help by progrmming my own Discord bot. I wantet to write in the Code "LogLevel = LogLevel.Debug, UseInternalLoghandler = true" but Visulas studio makes two errors. It says that there is no definition of LogLevel and UnseInternalLoghandler. Can somebody help me? Maybe i fogot a "using" + ..., but i dont know

I have the similar error, and I managed to fix the Loglevel.Debug but can't fix UseInterNalLogHandler.
So for LogLevel.Debug you can use this.
Microsoft.Extensions.Logging.LogLevel.Debug
Or just using Microsoft.Extensions.Logging.LogLevel.Debug at the
top of the code.
Sorry can't help with the UseInternalLoghandler.

Related

React native crypto stream module is undefined

I'm giving a try with [react-native-crypto][1] in order to learn how to convert nodejs to be used in React Native project in the future. Unfortunately, I couldn't get it running successfully. I've faced an issue with stream is undefined. ERROR TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[0], "stream").Transform.call').
If you have ever faced a similar problem, I'm so grateful for your help.
Also, I attach the screenshot of the issue as the following
For anyone still trying to solve this issue, I have figured out a solution that worked for me. So within node_modules/cipher-base/index.js, the top of the file should have a line which defines the variable Transform as var Transform = require('stream').Transform. For some reason, it does not like the module stream and as such it needs to be changed to readable-stream. Therefore the variable Transform should now read var Transform = require('readable-stream').Transform.
From what I have gathered, the stream module it is trying to refer to isnt actually a module that can be used. The reason why it gets referenced however seems to be because the tsconfig.json file in the root directory specifies "stream": ["./node_modules/readable-stream"] as a path, almost as if to make stream refer to the readable-stream module, which in theory it should refer to when it is called. But in this case it doesnt happen so we need to explicitly define that we are refering to the readable-stream module.
Hope this helps anyone else out there and prevents others scratching their heads for hours on end like it did for me!
I have figured it out by editing in metro.config.js as the following:
resolver: {
extraNodeModules: {
stream: require.resolve('stream-browserify'),
}
},

Discord.js bot is there a way to check mention?

Attached below is a part of my code. What it does is that if I type "pain.throw #user" it will throw out an embed and some text. However, if I don't mention a user, my code doesn't work. Is there a way someone can show me to let the bot spit out a message and say "You have to mention someone for this to work" or something. Thank you. Any help is appreciated.
Simply add a
if (!usernamegedUser) return message.channel.send("Try again, except mention someone");
Under the
const usernamegedUser = message.mentions.users.first();

How to check if AXIOS POST request is sent?

I can't seem to figure out why my console.log(); isn't going off. It seems that everything after the await axios.post(); method doesn't go off? Even my handleClearData(); function isn't going off.
I'm using React with Axios for my contact form to send data to a NodeJS server to then email the data to my email.
Could anyone please explain to me or point me in the right direction on solving this problem? Also, the console.log(res); obviously doesn't return or log anything as well.
Thanks a ton!
UPDATED:
Here's more info. I even took out my function thinking it may have been the problem. It wasn't...
SECOND UPDATE:
Another update!
You'll want to put the console log under handleClearData(); within the (first) try block.
I managed to fix it because await method was waiting for a response from the server. So, on my backend I put this simple line of code, res.send() which then allowed the await function to get out of its infinite loop; therefore, executing the rest of the code that came after it.
Thanks to all that tried to help me! =)
&& happy coding!

express-validator custom() method doesn't work. How to debug it?

I'm trying to figure out why this custom validation always get ignored.
exports.validateData = [
// ...Other built-in validations that work...
body('field')
.custom((value) => {
console.log('This message shows up!')
return false
})
.withMessage('Wrong!'),
// ...Other built-in validations that work...
]
I never get the 'Wrong!' flash message.
My routes file looks like this:
router.post('/person/add',
personController.validateData,
asyncHandler(personController.createPerson)
)
Do you have any idea why this is happening? How can I debug it?
Please, let me know how I can improve my answer to get your help. :)
Sorry about my poor English.
Update: I've just found this GitHub issue about the exact same problem in the express-validator official repo. There is no solution yet.

Messenger bot does not respect the message order

I'm having an issue with Messenger dev platform and guessed I could ask you guys for some help.
I would like my bot to send multiple messages in a row, for exemple :
sendTextMessage(user, "Hello");
sendTextMessage(user, "Goodbye");
But since Node is asynchrone, the order is not always respected and sometimes 'Goodbye' ends up showing before 'Hello'.
What is the best solution to remedy this issue ?
Thanks for your help!
You can do this in NodeJS by using either callbacks or promises. If you are not familiar with either of them, you can read callbacks and promises.
For further more steps, please check this out:
https://stackoverflow.com/a/47497119/6874563
I used above and get solved.

Resources