Created
March 11, 2022 06:31
-
-
Save marckohlbrugge/620b0f793e015b687170553f42ffac42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make sure you have a .env file with DISCORD_CLIENT_ID set | |
require "dotenv/load" | |
require "http" | |
puts "Go to the following URL in your browser to authorize this application:" | |
puts "https://discord.com/api/oauth2/authorize?response_type=token&client_id=#{ENV.fetch("DISCORD_CLIENT_ID")}&scope=identify%20email%20connections%20guilds%20guilds.join%20guilds.members.read%20messages.read" | |
puts "" | |
puts "Paste the URL you were redirected to after authorization:" | |
output = gets.strip | |
puts "" | |
ENV["ACCESS_TOKEN"] = URI.parse(output).fragment.split("&")[1].split("=").last | |
BASE_URI = "https://discord.com/api/v9" | |
def get(end_point) | |
headers = { | |
"User-Agent" => "DiscordBot (https://google.com, 1)", | |
"Authorization" => "Bearer #{ENV.fetch("ACCESS_TOKEN")}" | |
} | |
uri = "#{BASE_URI}#{end_point}" | |
request = HTTP.headers(headers).get(uri) | |
JSON.parse(request.body.to_s) | |
end | |
guilds = get("/users/@me/guilds") | |
guilds.each do |guild| | |
puts guild["name"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment