Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2.  
  3. include __DIR__.'/vendor/autoload.php';
  4.  
  5. //Few variables to make things easier
  6. $token = 'NTIwMTI4NDI3Njg1MDUyNDE2.DupY6g.4H5bha3TLeg77ixFnBoICF006VI';
  7.  
  8.  
  9.  
  10. //Basic DiscordPHP stuff
  11. $discord = new \Discord\Discord([
  12.     'token' => $token,
  13. ]);
  14.  
  15. $discord->on('ready', function ($discord) {
  16.     echo "Bot is ready.", PHP_EOL;
  17.  
  18.     // Listen for events here
  19.     $discord->on('message', function ($message) {
  20.         echo "Recieved a message from {$message->author->username}: {$message->content}", PHP_EOL;
  21.     });
  22. });
  23.  
  24. use Discord\DiscordCommandClient;
  25.  
  26. $discord = new DiscordCommandClient([
  27.     'token' => $token,
  28.     'prefix' => '>'
  29. ]);
  30.  
  31. $servername = "localhost";
  32. $username = "root";
  33. $password = "";
  34. $dbname = "bhop";
  35.  
  36. $conn = new mysqli($servername, $username, $password, $dbname);
  37. if ($conn->connect_error) {
  38.     echo "Could not connect, connection failed with reason: " . $conn->connect_error;
  39. }
  40.  
  41. $sql = "SELECT * FROM times, players GROUP BY(maps) ORDER BY date desc LIMIT 10";
  42. $result = $conn->query($sql);
  43.  
  44. $discord->registerCommand('wr', function ($message) {
  45.     if($result->num_rows > 0) {
  46.         //outputting data of each row
  47.         echo '<table>';
  48.         echo '<tr>';
  49.         echo '<th>Player</th>
  50.             <th>Map</th>
  51.             <th>Time</th>
  52.             <th>Style</th>';
  53.         echo '<tr>';
  54.         while($row = $result->fetch_assoc()) {
  55.             echo '<tr>';
  56.             echo ' <td>' . $row["players"] . '</td>';
  57.             echo ' <td>' . $row["maps"] . '</td>';
  58.             echo ' <td>' . $row["times"] . '</td>';
  59.             echo ' <td>' . $row["style"] . '</td>';
  60.             echo ' </tr> ';
  61.         }
  62.         echo '</table>';
  63.     }
  64.     else {
  65.         return "No record found to display";
  66.     }
  67.         /*this outputs the data of each row
  68.         while($row = $result->fetch_assoc()) {
  69.             echo "Player: " . $row["player"].  " - Map: " .  $row["maps"].  " - Time: "  . $row["time"]. " - Style: " . $row["style"]. "<br>"; */
  70. });
  71.  
  72. $discord->registerCommand('ping', function ($message) {
  73.     return 'pong!';
  74. });
  75.  
  76. $discord->registerCommand('shutdown', function ($discord) {
  77.     $discord->close();
  78. });
  79.  
  80. $discord->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement