Is it possible to enter a discord channel using the Dev Console (Ctrl + Shift + I)?
Something like "client.openChannel("channel_id")"
or a fetch that will load the channel?
More specifically this
but without having to have the user in friends or having the user ID.
With the user ID you can just use this
fetch("https://discord.com/api/v8/users/#me/channels", {
"headers": {
"accept": "*/*",
"accept-language": "en-US",
"authorization": "mfa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"content-type": "application/json",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-context-properties": "",
"x-super-properties": ""
},
"referrer": "https://discord.com/channels/#me",
"referrerPolicy": "no-referrer-when-downgrade",
"body": "{\"recipients\":[\"USER_ID\"]}",
"method": "POST",
"mode": "cors",
"credentials": "include"
});
And it'll open the DMs with that user but for some I only have the channel ID.
This is not an exact answer but a workaround that should work in some cases.
I got all the channels IDs from the "Request my data" on "Privacy and Safety".
Once I got the channels IDs on file.zip/messages/index.json I grabbed all those IDs and called
let channels = ['54623165841324165','54623165841324165','54623165841324165']
async function get_Channel_Data() {
let channel_id = channels.pop();
await sleep(2000);
let response = await fetch("https://discord.com/api/v8/channels/" + channel_id, {
"headers": {
"accept": "*/*",
"accept-language": "en-US",
"authorization": "mfa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin"
},
"referrer": "https://discord.com/channels/#me",
"referrerPolicy": "no-referrer-when-downgrade",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
let data = await response.json();
// data.type 1 is a DM, data.type 0 is server
if (data.type == 1) {
// This is the user ID of the person you DM
console.log(data.recipients[0].id);
}
get_Channel_Data();
}
Then for each user ID call
let user_ids = ['54623165841324165','54623165841324165','54623165841324165']
async function open_dms() {
let user_id = user_ids.pop();
if (user_id === undefined) {
console.log("END");
return false;
}
await sleep(2000);
let response = await fetch("https://discord.com/api/v8/users/#me/channels", {
"headers": {
"accept": "*/*",
"accept-language": "en-US",
"authorization": "mfa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"content-type": "application/json",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin"
},
"referrer": "https://discord.com/channels/#me",
"referrerPolicy": "no-referrer-when-downgrade",
"body": "{\"recipients\":[\""+user_id+"\"]}",
"method": "POST",
"mode": "cors",
"credentials": "include"
});
let data = await response.json();
open_dms();
}
to open the DM with that user ID
Related
Post request works but response (on code 200) is not returned.
`axios
.post(url, JSON.stringify(data))
.then((resp) => {
console.log("resp: ", resp.data.body);
console.log("result: ", resp.data.result);
alert(Success ${JSON.stringify(resp.data.result)});
})
.catch((err) => {console.error("Problem with Add: ", err); }); };`
When running the same request in postman i get the response with custom error:
`{
"statusCode": 200,
"headers": {
"Content-Type": "application/json",
"Access-Control-Allow-Headers": "",
"Access-Control-Allow-Origin": "",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Credentials": true
},
"body": ""Success"",
"result": [
{
"#full_error": "ERROR 1062 (23000): Duplicate entry '501151' for key 'PRIMARY'"
}]}`
Please advise
An example of the rapidapi google translate API code for the JavaScript fetch method is:
fetch("https://google-translate1.p.rapidapi.com/language/translate/v2", {
"method": "POST",
"headers": {
"x-rapidapi-host": "google-translate1.p.rapidapi.com",
"x-rapidapi-key": "MY-API-KEY",
"accept-encoding": "application/gzip",
"content-type": "application/x-www-form-urlencoded"
},
"body": {
"source": "en",
"q": "Hello, world!",
"target": "es"
}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
})
Now I copied it, and used it for the React component as follows:
fetch("https://google-translate1.p.rapidapi.com/language/translate/v2", {
method: "POST",
body: {
"source": "en",
"q": "Hello, world!",
"target": "es"
},
headers: {
"x-rapidapi-host": "google-translate1.p.rapidapi.com",
"x-rapidapi-key": "MY-API-KEY",
"accept-encoding": "application/gzip",
"content-type": "application/x-www-form-urlencoded"
}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
})
After running the program, I get the error "POST https://google-translate1.p.rapidapi.com/language/translate/v2 502 (Bad Gateway)" on the console!
How can I have a healthy connection to the server?
this code solved the same problem for me
<script>
const key = "your key"
const qs = obj => {
return new URLSearchParams(obj).toString();
}
const word = "Hello, world";
const data = qs({
q: word,
source: "en",
target: "es",
})
const options = {
method: "POST",
url: "https://google-translate1.p.rapidapi.com/language/translate/v2",
headers: {
"content-type": "application/x-www-form-urlencoded",
"x-rapidapi-key": key,
"x-rapidapi-host": "google-translate1.p.rapidapi.com",
},
data: data,
};
axios.request(options).then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(99, error);
});
</script>
My url if opened on browser gives the following error:(attached image)
Body of my api call looks like below :
{
"entityId": 4071,
"listViewId": 0,
"asLookup": false,
"retrieveAllFields": true,
"fullTextSearch": "",
"query": [
],
"pagination": {
"pageNumber": 0,
"recordsCountPerPage": 0
},
"sorting": {
"fieldId": 0,
"direction": 0
}
}
I am calling api in react native using fetch below :
try {
let response = await fetch('url', {
method: 'POST',
headers: {
'tenantid': '1',
'Content-Type': 'application/json',
'language': '0',
},
body: JSON.stringify({
entityId: 4071,
listViewId: 0,
asLookup: false,
retrieveAllFields: true,
fullTextSearch: "",
query: [
],
pagination: {
pageNumber: 0,
recordsCountPerPage: 0
},
sorting: {
fieldId: 0,
direction: 0
}
})
})
let json = await response.json();
console.log("This is response" + json)
this.setState({records: json.results, isFetching:false});
}catch(error){
this.setState({errorMessage:error})
console.log("This is error"+error)
}
This gives me response : Network failed request. Also tried with the inverted commas, still same response. I am newbie in react native but I have made api calls in the past but this one wouldnt work. If anyone can look into this, would be of great help!
did you use the correct url ?
it should looks like something like this
fetch('https://mywebsite.com/endpoint/', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
firstParam: 'yourValue',
secondParam: 'yourOtherValue'})
}).then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
});
maybe you should look on the documentations
https://reactnative.dev/docs/network
I have the following code to retrieve an image from an API
await fetch('https://example.com/api/user/fileaccess', {
method: 'POST',
headers: {
Accept: '*',
'Content-Type': 'application/json',
'token':'xxxxxxxxxxxxxxxxxxxxxxxx'
},
body: JSON.stringify({"applicantid": xxxx, "user_secret": "xxxxxxxxxxx","fileid":xxxxx}),
}).then((response) => {
console.log(response);
});
The request was completed and i got log in my console.
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId":
"xxxxx-xxxx-xxx-xxxx-xxxxx", "offset": 0, "size": 953328}},
"_bodyInit": {"_data": {"__collector": [Object], "blobId":
"xxxxx-xxxx-xxxx-xxxx-xxxxx", "offset": 0, "size": 953328}},
"headers": {"map": {"cache-control": "max-age=2592000", "connection":
"Keep-Alive", "content-type": "image/jpeg", "date": "Tue, 04 Feb 2020
10:34:14 GMT", "expires": "Thu, 05 Mar 2020 10:34:14 GMT",
"keep-alive": "timeout=5, max=100", "pragma": "public", "server":
"Apache", "transfer-encoding": "chunked"}}, "ok": true, "status": 200,
"statusText": undefined, "type": "default", "url":
"https://example.com/api/user/fileaccess"}
My question is, How to display this data as an image in my app? Is it possible to convert a base64 from this data?
You need to extract it into json or text or some other data before you can do anything with the response.
As per Mozilla docs, A basic fetch request is really simple to set up. Have a look at the following code:
fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((myJson) => {
console.log(myJson);
});
So, modify your code as below :
fetch('https://example.com/api/user/fileaccess', {
method: 'POST',
headers: {
Accept: '*',
'Content-Type': 'application/json',
'token':'xxxxxxxxxxxxxxxxxxxxxxxx'
},
body: JSON.stringify({"applicantid": xxxx, "user_secret": "xxxxxxxxxxx","fileid":xxxxx}),
})
.then(response => response.json())
.then((result) => {
console.log("Your intended result is: " , result)
});
The response.json() is added just assuming the server is returning a JSON data.
If not, you can try the below methods too based on your server implementation.
arrayBuffer()
blob()
json()
text()
formData()
If that's the image URL you can go ahead as follows
Store image in your state
this.setState({image:res.url})
and then <Image source={{uri:this.state.image}}/>
I am working in a project where to search from firebase data using elastic search and trying to add data to elastic using angularjs but giving error as :
{"data":"","status":0,"config":{"method":"PUT","transformRequest":[null],"transformResponse":[null],
my code is:
var inputJson =
{
"mappings": {
"carprev": {
"properties": {
"agepolicy33": {
"type": "text"
},
"aircondition33": {
"type": "text"
},
"year33": {
"type": "integer"
}
}
}
}
}
var corsHeaders = {
origin: ["*"],
headers: ['Origin', 'X-Requested-With', { 'Content-Type':
'application/x-www-form-urlencoded' }],
credentials: true,
additionalHeaders: ['access-control-allow-headers', 'Access-Control-
Allow-Origin, Access-Control-Allow-Headers, Origin, X-Requested-With,
Content-Type, CORRELATION_ID'],
additionalExposedHeaders: ['access-control-allow-headers', 'Access-
Control-Allow-Origin, Access-Control-Allow-Headers, Origin, X-
Requested-With, Content-Type, CORRELATION_ID']
};
$http({
method: "PUT",
// headers: ['Origin', 'X-Requested-With', 'Content-Type'],
url: "http://xx.xxx.xxx.xxx/elasticsearch/test/5",
data: inputJson
}).then(function mySuccess(response) {
console.log(response);
}, function myError(err) {
var cjson = JSON.stringify(err);
console.log(err);
});
but the same json in inserted into elasticsearch using postman and query data to retrieve from elastic
if anyone can resolve, appreciated
You can try changing the content type to json.
$http({
method: "PUT",
headers: {'Content-Type': 'application/json'},
url: "http://xx.xxx.xxx.xxx/elasticsearch/test/5",
data: inputJson
}).then(function mySuccess(response) {
console.log(response);
}, function myError(err) {
var cjson = JSON.stringify(err);
console.log(err);
});