diff --git a/demos/simple-demo/config.php b/demos/simple-demo/config.php
index 804bbb0..97d83af 100644
--- a/demos/simple-demo/config.php
+++ b/demos/simple-demo/config.php
@@ -17,6 +17,12 @@
# example: https://mydomain.com/test/includes/login.php
$redirect_url = "";
+
+# GETTING CHANNELS
+# - Setting the variable below with server ID will provide you with access to all the channels inside the server.
+$guild_id = null;
+
+
# IMPORTANT READ THIS:
# - Set the `$bot_token` to your bot token if you want to use guilds.join scope to add a member to your server
# - Check login.php for more detailed info on this.
diff --git a/demos/simple-demo/includes/discord.php b/demos/simple-demo/includes/discord.php
index c421318..ed09d9e 100644
--- a/demos/simple-demo/includes/discord.php
+++ b/demos/simple-demo/includes/discord.php
@@ -12,7 +12,8 @@
$GLOBALS['base_url'] = "https://discord.com";
# Setting bot token for related requests
-$GLOBALS['bot_token'] = null;
+require "../config.php";
+$GLOBALS['bot_token'] = $bot_token;
# A function to generate a random string to be used as state | (protection against CSRF)
function gen_state()
@@ -55,6 +56,21 @@ function init($redirect_url, $client_id, $client_secret, $bot_token = null)
$_SESSION['access_token'] = $results['access_token'];
}
+# A function to get the channels in a guild | (requires bot token)
+function get_channels($guild_id)
+{
+ $url = $GLOBALS['base_url'] . "/api/guilds/$guild_id/channels";
+ $headers = array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bot ' . $GLOBALS['bot_token']);
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, $url);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+ $response = curl_exec($curl);
+ curl_close($curl);
+ $results = json_decode($response, true);
+ return $results;
+}
+
# A function to get user information | (identify scope)
function get_user($email = null)
{
diff --git a/demos/simple-demo/includes/login.php b/demos/simple-demo/includes/login.php
index fb1fca5..d1238e3 100644
--- a/demos/simple-demo/includes/login.php
+++ b/demos/simple-demo/includes/login.php
@@ -37,6 +37,12 @@
# Adding user to guild | (guilds.join scope)
# join_guild('SERVER_ID_HERE');
+# Fetching guild channels | (guilds scope)
+
+if($guild_id != null) {
+ $_SESSION['channels'] = get_channels($guild_id);
+}
+
# Fetching user guild details | (guilds scope)
$_SESSION['guilds'] = get_guilds();
diff --git a/demos/simple-demo/index.php b/demos/simple-demo/index.php
index 7531005..6d2b630 100644
--- a/demos/simple-demo/index.php
+++ b/demos/simple-demo/index.php
@@ -84,6 +84,26 @@
?>
+
NAME | +ID | +"; + echo $_SESSION['channels'][$i]['name']; + echo " | "; + echo $_SESSION['channels'][$i]['id']; + echo " | "; + echo ""; + } + ?> +
---|
diff --git a/discord.php b/discord.php index c421318..ed09d9e 100644 --- a/discord.php +++ b/discord.php @@ -12,7 +12,8 @@ $GLOBALS['base_url'] = "https://discord.com"; # Setting bot token for related requests -$GLOBALS['bot_token'] = null; +require "../config.php"; +$GLOBALS['bot_token'] = $bot_token; # A function to generate a random string to be used as state | (protection against CSRF) function gen_state() @@ -55,6 +56,21 @@ function init($redirect_url, $client_id, $client_secret, $bot_token = null) $_SESSION['access_token'] = $results['access_token']; } +# A function to get the channels in a guild | (requires bot token) +function get_channels($guild_id) +{ + $url = $GLOBALS['base_url'] . "/api/guilds/$guild_id/channels"; + $headers = array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bot ' . $GLOBALS['bot_token']); + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + $response = curl_exec($curl); + curl_close($curl); + $results = json_decode($response, true); + return $results; +} + # A function to get user information | (identify scope) function get_user($email = null) {