Discord JS 12.5.3 messageUpdate have trouble - discord.js

i added messageUpdate for my bot's modlogs like this:
c.on("messageUpdate", function(oldMessage, newMessage) {
if (oldMessage.channel.type !== "text") return;
if (newMessage.channel.type !== "text") return;
if (oldMessage.content === newMessage.content) return;
send_log(
c,
oldMessage.guild,
"YELLOW",
"Message UPDATED",
`
**Author : ** <#${newMessage.author.id}>
**Date : ** <t:${parseInt(newMessage.createdTimestamp / 1000)}:R>
**Channel : ** <#${newMessage.channel.id}>
**Orignal Message : **
\`\`\`
${oldMessage.content.replace(/`/g, "'")}
\`\`\`
**Updated Message : **
\`\`\`
${newMessage.content.replace(/`/g, "'")}
\`\`\``
);
});
it worked fine for a few minutes: output image
then my bot got into exit status 1 because of this:
**Author : ** <#${newMessage.author.id}>
^
TypeError: Cannot read property 'id' of null
at Client.<anonymous> (/home/runner/hibikibanmai-bot/events/client/logger.js:286:37)

Maybe add:
if (!newMessage.author) return;

Related

"Error: Attempt to set read-only RecoilValue: " when using useRecoilState

dd
const [ book, setBook ] = useRecoilState(axiosSelector)
const clickHandlerName = () =>{
const _book = [...book].sort((a, b) => (a.title > b.title) ? 1 : -1)
console.log(_book)
setBook(_book)
}
Error message -
Uncaught Error: Attempt to set read-only RecoilValue:
nothing's changing the 'book' state directly but why is that error showing up?
(the conole logging is working just fine, i believe the problem must have to do with "setBook(_book)" line)

discord.js v13 bot uptime

I made some bot uptime code but got an error showing 52 years ago The code is below.
const style = 'R'
const starttime = `<t:${Math.floor(client.readyAt / 1000)}` + (style ? `:${style}` : '') + '>'
client.on('messageCreate' , message=>{
if(message.content == "!uptime"){
message.reply(`uptime!\n uptime : ${starttime}`)
}
})
You are setting that outside of the event, where client.readyAt is null. When you divide null by anything except for 0, you get 0. The result would then be <t:0:R>. You could either make this a function, or set it in the event
function generateReadyTimestamp() {
return `<t:${Math.floor(client.readyAt / 1000)}` + (style ? `:${style}` : '') + '>'
}
// ...
message.reply(`uptime!\n uptime : ${generateReadyTimestamp()}`)
Or, setting it inside the callback:
client.on('messageCreate', message => {
if(message.content == "!uptime"){
const starttime = `<t:${Math.floor(client.readyAt / 1000)}` + (style ? `:${style}` : '') + '>'
message.reply(`uptime!\n uptime : ${starttime}`)
}
})

Discord bot not responding to command

I'm trying to code the bot to generate a random percentage when the command !percent is used while also mentioning the user. When I use the command it doesn't seem to work but no errors pop up in the console.
if (message.content == ("!Percent" || message.content == "!percent")) {
if (message.isMemberMentioned()) {
message.isMemberMentioned.users.forEach((k, v) => {
message.channel.send( v + ' is ' + ( Math.floor(Math.random() * 100) + 1 ) + "% ! " );
})
}
}
})
I think you want
if(message.content.toLowerCase() === '!percent'){...
or..
if(['!Percent', '!percent'].includes(message.content)){...
Not
if (message.content == ("!Percent" || message.content == "!percent")) {...
Is wrong as its comparing message content, a string, to a boolean as "!Percent" will always be true.
The Message class doesn't have a #isMemberMentioned method documented (never existed??) if you want support for that edit your post with the function code. Same goes for the isMemberMentioned property on the Message class variable.

i see "405: Method Not Allowed" when trying following code on Python 3.8.3

https://tutorialedge.net/python/create-rest-api-python-aiohttp/
from aiohttp import web
import json
async def handle(request):
response_obj = { 'status' : 'success' }
return web.Response(text=json.dumps(response_obj))
async def new_user(request):
try:
print("AT Epoint" )
## happy path where name is set
user = request.query['name']
## Process our new user
print("Creating new user with name: " , user)
response_obj = { 'status' : 'success' }
## return a success json response with status code 200 i.e. 'OK'
return web.Response(text=json.dumps(response_obj), status=200)
except Exception as e:
print("AT EXCEPTION" )
## Bad path where name is not set
response_obj = { 'status' : 'failed', 'reason': str(e) }
## return failed with a status code of 500 i.e. 'Server Error'
return web.Response(text=json.dumps(response_obj), status=500)
Once you have implemented the listener function, register it with the aiohttp instance.
app.router.add_post('/user', new_user)
Source: TutorialEdge

Manage http error codes with Codename One

I wrote:
private RequestBuilder getPostRequest(String api) {
return Rest.post(url + api)
.jsonContent()
.header("wsc-access-key", WowzaAccount.getAccessKey())
.header("wsc-api-key", WowzaAccount.getRestKey());
}
getPostRequest("live_streams").body(json).fetchAsJsonMap(new OnComplete<Response<Map>>() {
#Override
public void completed(Response<Map> v) {
if (v.getResponseCode() == 201) {
// success
Map<String, Object> response = v.getResponseData();
name = (String) response.get("name");
id = (String) response.get("id");
connection_code = (String) response.get("connection_code");
Log.p("WowzaLiveStream -> (Code 201) Successfully created live stream with name " + name, Log.DEBUG);
onComplete.completed(instance);
} else if (v.getResponseCode() == 401) {
Log.p("WowzaLiveStream -> (Code 401) Unauthorized, failed to create live stream with name " + params.name.get(), Log.DEBUG);
onFail.run();
} else if (v.getResponseCode() == 422) {
Log.p("WowzaLiveStream -> (Code 422) Unprocessable Entity, failed to create live stream with name " + params.name.get(), Log.DEBUG);
onFail.run();
} else {
Log.p("WowzaLiveStream -> Unknow response with code " + v.getResponseCode() + ", failed to create live stream with name " + params.name.get(), Log.DEBUG);
onFail.run();
}
}
});
The problem is that when I get a 422 response code my onFail callback is not called. Instead a Dialog appears. I suppose that this dialog is invoked by the default addNetworkErrorListener code in the init(). However... I cannot (and I don't want to) disable the default addNetworkErrorListener code, because I'm writing a new CN1Lib. Instead I need that in this case, and only in this case, the network error listener should not be invoked and instead the failure callback that I wrote should be run.
It's more appropriate, in this case, to call the network error listener only if the Internet connection is lost.
Thank you
You need to explicitly catch the error code callback as the callback might have a different format than the main JSON:
private RequestBuilder getPostRequest(String api) {
return Rest.post(url + api)
.jsonContent()
.header("wsc-access-key", WowzaAccount.getAccessKey())
.header("wsc-api-key", WowzaAccount.getRestKey())
.onErrorCodeJSON(map -> {
// process error response
});
}

Resources