Advertisement
Cookins

Untitled

Mar 28th, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const axios = require('axios');
  3. const WebSocket = require('ws');
  4.  
  5. const client = new Discord.Client({
  6. intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS]
  7. });
  8.  
  9. const myIntents = new Discord.Intents();
  10. myIntents.add(Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS);
  11.  
  12. client.on('ready', () => {
  13. console.log(`Logged in as ${client.user.tag}!`);
  14. });
  15.  
  16. client.on('message', async message => {
  17. if (message.author.bot) return;
  18.  
  19. const channelId = 'YOUR_CHANNEL_ID';
  20.  
  21. if (message.channel.id === channelId) {
  22. const ws = new WebSocket('wss://api.wolvesville.com/gameplay', {
  23. headers: {
  24. 'Authorization': 'Bearer YOUR_API_KEY',
  25. 'User-Agent': 'DiscordBot'
  26. }
  27. });
  28.  
  29. ws.on('open', function open() {
  30. console.log('WebSocket connected!');
  31. ws.send(JSON.stringify({
  32. action: 'game_message',
  33. message: message.content
  34. }));
  35. ws.close();
  36. });
  37.  
  38. ws.on('error', function error(err) {
  39. console.error(err);
  40. });
  41. }
  42. });
  43.  
  44. const ws = new WebSocket('wss://api.wolvesville.com/gameplay', {
  45. headers: {
  46. 'Authorization': 'Bearer YOUR_API_KEY',
  47. 'User-Agent': 'DiscordBot'
  48. }
  49. });
  50.  
  51. ws.on('open', function open() {
  52. console.log('WebSocket connected!');
  53. ws.send(JSON.stringify({
  54. action: 'game_status'
  55. }));
  56. });
  57.  
  58. ws.on('message', function incoming(data) {
  59. const gameMessage = JSON.parse(data);
  60.  
  61. if (gameMessage.action === 'game_message') {
  62. const channelId = 'YOUR_CHANNEL_ID';
  63. const channel = client.channels.cache.get(channelId);
  64. channel.send(`**${gameMessage.author}**: ${gameMessage.message}`);
  65. }
  66. });
  67.  
  68. ws.on('error', function error(err) {
  69. console.error(err);
  70. });
  71.  
  72. client.login('YOUR_BOT_TOKEN');
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement