Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const axios = require('axios');
- const WebSocket = require('ws');
- const client = new Discord.Client({
- intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS]
- });
- const myIntents = new Discord.Intents();
- myIntents.add(Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS);
- client.on('ready', () => {
- console.log(`Logged in as ${client.user.tag}!`);
- });
- client.on('message', async message => {
- if (message.author.bot) return;
- const channelId = 'YOUR_CHANNEL_ID';
- if (message.channel.id === channelId) {
- const ws = new WebSocket('wss://api.wolvesville.com/gameplay', {
- headers: {
- 'Authorization': 'Bearer YOUR_API_KEY',
- 'User-Agent': 'DiscordBot'
- }
- });
- ws.on('open', function open() {
- console.log('WebSocket connected!');
- ws.send(JSON.stringify({
- action: 'game_message',
- message: message.content
- }));
- ws.close();
- });
- ws.on('error', function error(err) {
- console.error(err);
- });
- }
- });
- const ws = new WebSocket('wss://api.wolvesville.com/gameplay', {
- headers: {
- 'Authorization': 'Bearer YOUR_API_KEY',
- 'User-Agent': 'DiscordBot'
- }
- });
- ws.on('open', function open() {
- console.log('WebSocket connected!');
- ws.send(JSON.stringify({
- action: 'game_status'
- }));
- });
- ws.on('message', function incoming(data) {
- const gameMessage = JSON.parse(data);
- if (gameMessage.action === 'game_message') {
- const channelId = 'YOUR_CHANNEL_ID';
- const channel = client.channels.cache.get(channelId);
- channel.send(`**${gameMessage.author}**: ${gameMessage.message}`);
- }
- });
- ws.on('error', function error(err) {
- console.error(err);
- });
- client.login('YOUR_BOT_TOKEN');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement