so i have a cmd in a cog that suppose to set the welcome channel "welcomec" and from that its supposed to take that info and use it to post the message in the guild welcome channel but doesnt seem to work ngl can anyine help me
edited: after changing it to what RiVen told me i got a new error that I don't understand at all
main code:
welcome: event
#fright.event
async def on_member_join(member):
fright.db = fright.mongo['fright']
fright.welcome = discordmongo.Mongo(connection_url=fright.db, dbname="welcome")
dbguild = await fright.welcome.find({"_id": member.guild.id})
dbchannel = await fright.welcome.find({"welcomec": member.guild.id})
wguild = fright.get_guild(dbguild)
wchannl = await fright.fetch_channel(dbchannel)
await wchannl.send('worksss')
error:
raise HTTPException(r, data) discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body In channel_id: Value "None
NoneType error means that it doesn't correctly recognize the channel. When you use get_channel you are looking for the channel in the bot's cache which might not have your channel. You could use fetch_channel instead - which is an API call.
wchannl = await fright.fetch_channel(dbchannel)
Related
I have a List, and I need to send each element of this List to the server sequentially. And if the answer is with an error, then do not continue sending, but display an error. I am trying to use
await Future.wait([]);
but I do not quite understand how to complete the send on failure, and how to iterate over the elements.
To iterate over elements through .forEach(element) {}
The compiler throws an error: The argument type 'List' can't be assigned to the parameter type 'Iterable<Future>'
Here is what I am trying to do:
await Future.wait([
state.revisionFill.forEach((element) {
var successOrFail = await ContainerExpire.call(ContainerExpireParams(token: token, entity: element.entity));
})
]);
I'm new and don't fully understand async/sync requests in flutter. Tell me which direction to study.
How to complete the next send if it fails?
This seems to be what you're looking for:
for (var element in state.revisionFill) {
var successOrFail = await ContainerExpire.call(ContainerExpireParams(token: token, entity: element.entity));
if (successOrFail.hasFailed()) {
//add code for some possible error handling
break;
}
}
I am assuming that based on the value of successOrFail you can tell whether or not an error occured. Basically after each request you check for the status, and break on an error. You can add logic for displaying your error message.
Help is much appreciated how to trace down this issue, because I am running out of ideas.
I am calling the function getOrderCollection, below, but it aborts after the first line var myCompanyDoc = await FirebaseFirestore.instance.collection('companies').doc(myCompany).get(); Without trowing anything to the console or jumping into some library when debugging. When I click next statement it jumps back to the calling function.
I am authenticated to the database, companyCollection = FirebaseFirestore.instance.collection('companies') provides an initialized object pointing to the collection and myCompany is a constant with the document id entered by copy/paste.
If some rules for the database but I can't see successful or denied queries with the monitor.
Any ideas how I can proceed tracing down the issue?
Future<void> getOrderCollection() async {
var myCompanyDoc = await FirebaseFirestore.instance.collection('companies').doc(myCompany).get();
print("companyDoc fetched");
final myDeliveryDocRef = myCompanyDoc.data()['delivery'].toString();
orderCollection = FirebaseFirestore.instance.collection('companies').doc(myCompany).collection('features').doc(myDeliveryDocRef).collection('orders');
orderBriefDoc = FirebaseFirestore.instance.collection('companies').doc(myCompany).collection('features').doc(myDeliveryDocRef);
}
UPDATE: This is collection > document what corresponds to final String myCompany = '4U4kZKXkr3rHA6B04S5K';
As we discussed in your comments, the issue was that you forgot to await the getOrderCollection() function. Even though, as you mentioned, your caller function _deliveryRepository.initRepository() was awaited, you still had to await getOrderCollection() inside your caller method to make sure that the code is waiting for the getOrderCollection() to be executed before it proceeds to the next line.
In general, you want to have some error handling and to type the known types/classes (avoid using var).
Error handling - for async/await place the code inside a try/catch.
Typing - Dart is type safe, which is really great to prevent runtime errors.
Depending on your setup, you might be able to hover over the Firestore.instance.collection(...).doc(...) to see the return type. .doc(...).get() returns a DocumentSnapshot and .collection(...).get() returns a CollectionSnapshot.
Using the above, it should be easier to debug:
Future<void> getOrderCollection() async {
try {
DocumentSnapshot myCompanyDoc = await FirebaseFirestore.instance.collection('companies').doc(myCompany).get();
print("companyDoc fetched");
final myDeliveryDocRef = myCompanyDoc.data()['delivery'].toString();
} catch(e) {
print('Error: ' + e.toString());
}
}
Don't forget to await your other 2 Firestore queries.
Hi I tried to catch a socketException when the server I am consulting is not available, I tried with try{}catch{}, catchError and timeout, but it doesn't work
I need that if some time passes that the server does not respond, that it already stops waiting for it
The error is :
and I tried something like this
You are probably giving the code the wrong URL. Maybe this link will help You. Link. If You could just type in the URL and If You are using Python with flask or Django, or Node.js, that would help tremendously.
Update:
In the part where You say
final resp = await http.get(url).catchError({(onError) => print(onError)});
You should change it to this:
final resp = await http.get(url).catchError((onError) {
print(onError);
return null;
});
Because You are catching the Error in the response and only printing it. You should return null; and escape that function.
I hope this helped.
I am trying to validate an Instagram username, that the user should enter. I want to find out whether an account with the username exists or if not. I have tried it this way:
final request = await http.get('https://www.instagram.com/$username/');
if (request.statusCode != 404) {
...
}
I also looked at a similar question: Check if instagram account name is available
The link that is mentioned in the answer:(https://www.instagram.com/username/?__a=1) works fine in the browser
(If the username exists, it shows all the information of the account, if it doesn't it shows two brackets that are empty)
but in my code I don't get statusCode 404 I get statusCode 200.
I also can't catch an error.
It is the same with the link from my code (https://www.instagram.com/$username/), I get statusCode 200.
Is there a different way that I have not yet considered?
Thanks for your answers in advance!
It's just a http request, if you are getting a success status so check the body in the request, for example if you get a success code but the body is empty {} you can decode the body response and check it in this way:
void checkUser() async {
final request = await http.get('https://www.instagram.com/fakeUserExample/?__a=1');
final decodeData = json.decode(request.body);
if(decodeData.isEmpty){
print(".:: User Not Found ::.");
}
}
Don't forget to import the import 'dart:convert';
Hope it helps.
I am trying to upload a video and encode it via azure rest service.
I have now hit the step of encoding the video but I am having difficulties with the request.
The following code shows my request:
var joburl = res.RequestMessage.RequestUri + "Jobs";
client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
client.DefaultRequestHeaders.Add("x-ms-version", "2.8");
client.DefaultRequestHeaders.Add("DataServiceVersion", "3.0");
client.DefaultRequestHeaders.Add("MaxDataServiceVersion", "3.0");
client.DefaultRequestHeaders.Add("x-ms-date", date);
//accept
t = new NameValueHeaderValue("odata", "verbose");
type = new MediaTypeWithQualityHeaderValue("application/json");
type.Parameters.Add(t);
client.DefaultRequestHeaders.Accept.Add(type);
result = await client.PostAsync(joburl,json);
the url:https://wamsamsclus001rest-hs.cloudapp.net/api/Jobs
the json:
{"Name":"khgfiuydencodingjob","InputMediaAssets":[{"__metadata":{"Uri":"https://wamsamsclus001rest-hs.cloudapp.net/api/Assets('nb%3acid%3aUUID%3ad037b321-cd1c-43a9-9607-c4910fa7a85b')"}}],"Tasks":[{"Configuration":"H264 Adaptive Bitrate MP4 Set 720p","MediaProcessorId":"nb:mpid:UUID:1b1da727-93ae-4e46-a8a1-268828765609","TaskBody":"<?xml version=\"1.0\"encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"}]}
The bearer token works as I use it for other request.
But I get a bad request 400 with the followin error message:
{"error":{"code":"","message":{"lang":"en-US","value":"Parsing request content failed due to: Make sure to only use property names that are defined by the type"}}}
Can anyone spot the error.
Thank you for the help
Okay I got it to work. Needed a odata=verbose in my json/string content - like this:
var jobInJson = JsonConvert.SerializeObject(job);
json = new StringContent(jobInJson, Encoding.UTF8);//,
json.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose");
I tried this earlier however I got a error 500 but now it is working.