First of all, massive give thanks you to General Wrex#8129 at the DBM Mods server with helping me effigy this out! This is a command that lets you search for images from Imgur and posts 1 random motion-picture show from the search as a message.
As a requirement, this command needs DBM Beta and https://github.com/Discord-Bot-Maker-Mods/DBM-Mods/tree/beta-1.8.2 in order to work.
To brainstorm with, register your program with imgur's API in guild to get a Client ID, located here: https://api.imgur.com/oauth2/addclient , with the callback URL gear up as https://www.getpostman.com/oauth2/callback
Press submit, and copy downwards the Client ID it gives you. Going back to DBM, create a new command to house this pain.
For your kickoff action, make it
Store Command Params with the source info as one param , param number of 1 , and a temp variable of search.
The second action is where things become complicated. Brand a Run Script action with End Beliefs set as Do Not Phone call Next Activeness , Interpretation Style every bit either (don't recall information technology matters too much), and Store In to Nada .
The script you demand in is this, and make you put your Customer ID nether
var client_id !:
var request = this.getWrexMods().crave("asking"); var url = "https://api.imgur.com/3/gallery/search/?q=" + tempVars("search"); var client_id = "<PUT YOUR CLIENT ID Here>"; var tempVarName = "imgur"; endeavour { asking.get({ url: url, json: true, headers: { 'Say-so': 'Client-ID ' + client_id } }, (err, res, data) => { if (err) { panel.error(err.stack ? err.stack : err); } this.storeValue(information, ane, tempVarName, cache); this.callNextAction(cache); }); } catch (err) { console.error(err.stack ? err.stack : err); }
At present this is where things start getting easier. Make your 3rd action a
Generate Random Number activity. This is and then you don't go the same image every time yous call it. Set your
Minimum Range to
0,
Maximum Range to
60, and make it a
Temp Variable named
range.
4th action is really parsing the script. Create a Parse From Stored Json, setting End Beliefs to Telephone call Next Action Automatically, Stored JSON Variable Name to imgur, the JSON path to $.data[${tempVars("range")}].id, and store information technology in a Temp Variable named imgur_image.
The fifth and final activeness is just a Transport Message, with the message of https://imgur.com/gallery/${tempVars("imgur_image")} inside. You tin send it to whatsoever yous want, and it doesn't need to be stored.
And there you accept information technology! You can now search for images on Imgur! Hither's a show and tell:
Skillful luck, have fun, and happy holidays!
0 Response to "Discord Bot How to Upload Images From Imgur Command Python"
Post a Comment