I think it could be a good idea to display some of the latest Discord messages on the website. New visitors might be more inclined to stick around if they know there's more activity than just what they see on the site. I've written some quick example code for fetching the latest messages from a channel using RestCord:
<?php
// Step 0: Install RestCord (Composer: restcord/restcord)
// Step 1: Go to https://discordapp.com/developers/applications/ and register a new application
// Step 2: Create a bot for that application
// Step 3: Go to https://discordapp.com/oauth2/authorize?&client_id=502232355797204994&scope=bot&permissions=66560 (replace 502232355797204994 with your application's client id) and make the bot join the relevant server
// Step 4: Update the definitions below
define("BOT_TOKEN", "NTAyMjMyMzU1Nzk3MjA0OTk0.DqlD6w.uOnSIKcM7N0oG6srQN8vUBqsM3Q");
define("DISCORD_SERVER_ID", 502229064434712585);
define("CHANNEL_ID", null); // <- Define for one request fewer (since we don't have too look up the ID from the name)
define("CHANNEL_NAME", "general");
define("CHANNEL_TYPE", 0); // 0 for text channel (see https://discordapp.com/developers/docs/resources/channel#channel-object-channel-types)
require_once __DIR__ . "/vendor/autoload.php";
use RestCord\DiscordClient;
use Psr\Log\LoggerInterface;
class SilentLoggerReplaceWithSomethingBetterOrUseTheDefaultLogger implements LoggerInterface {
public function emergency($message, array $context = array()) {}
public function alert($message, array $context = array()) {}
public function critical($message, array $context = array()) {}
public function error($message, array $context = array()) {}
public function warning($message, array $context = array()) {}
public function notice($message, array $context = array()) {}
public function info($message, array $context = array()) {}
public function debug($message, array $context = array()) {}
public function log($level, $message, array $context = array()) {}
};
$discordClient = new DiscordClient(["token" => BOT_TOKEN, "logger" => new SilentLoggerReplaceWithSomethingBetterOrUseTheDefaultLogger()]);
$channelId = CHANNEL_ID;
if($channelId === null) {
$guildChannels = $discordClient->guild->getGuildChannels(["guild.id" => DISCORD_SERVER_ID]);
foreach($guildChannels as $channel) {
if($channel->name === CHANNEL_NAME && $channel->type === CHANNEL_TYPE) {
$channelId = $channel->id;
break;
}
}
if($channelId === null) {
exit("Channel not found.\n");
}
}
echo "Channel ID: " . $channelId . "\n";
$messages = $discordClient->channel->getChannelMessages(["channel.id" => $channelId, "limit" => 5]);
echo "Messages:\n";
foreach($messages as $msg) {
$time = new DateTime($msg["timestamp"], new DateTimeZone("UTC"));
$author = $msg["author"]["username"];
$content = $msg["content"];
echo $time->format("Y-m-d H:i:s") . " " . $author . " wrote:\n" . $content . "\n\n\n";
}
?>
I'd offer to help with this beyond just this example code if you're interested in implementing this, but, you know, I'm lazy.
PS. The code formatting using backticks isn't working properly