Skip to content

Commit

Permalink
Updated to a non-ancient discord.js version
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Jul 22, 2022
1 parent 58cdf59 commit 96741ca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ DyscordBot/obj/Debug/
DyscordBot/config\.json

DyscordBot/node_modules/

DyscordBot/.idea
35 changes: 27 additions & 8 deletions DyscordBot/DyscordBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@ const { token, prefix, listeningPort, defaultChannel, verbose, cooldown, require
console.log("Config loaded.");

var connectedToDiscord = false;
const Discord = require("discord.js");
const discordClient = new Discord.Client({ autoReconnect: true });
const { Client, GatewayIntentBits } = require("discord.js");

const discordClient = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildScheduledEvents
] });

var messageQueue = JSON.parse("{}");

Expand Down Expand Up @@ -43,7 +62,7 @@ function command(socket, message, client)

function setChannelTopic(channelID, topic)
{
var verifiedChannel = discordClient.channels.get(channelID);
var verifiedChannel = discordClient.channels.cache.get(channelID);
if (verifiedChannel != null)
{
if (verifiedChannel.manageable)
Expand Down Expand Up @@ -148,7 +167,7 @@ tcpServer.on("connection", (socket) =>
});
for (var channelID in messageQueue)
{
var verifiedChannel = discordClient.channels.get(channelID);
var verifiedChannel = discordClient.channels.cache.get(channelID);
if (verifiedChannel != null)
{
//Message is copied to a new variable as it"s deletion later may happen before the send function finishes
Expand All @@ -173,7 +192,7 @@ tcpServer.on("connection", (socket) =>
}

// Send remaining message
if (message != null && message !== " " && message !== "")
if (message !== " " && message !== "")
{
verifiedChannel.send(message);
if (verbose)
Expand Down Expand Up @@ -203,7 +222,7 @@ tcpServer.on("connection", (socket) =>
if (data.message === "read ECONNRESET")
{
console.log("Plugin connection lost.");
var verifiedChannel = discordClient.channels.get(defaultChannel);
var verifiedChannel = discordClient.channels.cache.get(defaultChannel);
if (verifiedChannel != null)
{
verifiedChannel.send("```diff\n- Dystopia connection lost.```");
Expand Down Expand Up @@ -239,7 +258,7 @@ tcpServer.listen(listeningPort, () =>
discordClient.on("ready", () =>
{
console.log("Discord connection established.");
discordClient.channels.get(defaultChannel).send("```diff\n+ Bot Online.```");
discordClient.channels.cache.get(defaultChannel).send("```diff\n+ Bot Online.```");
discordClient.user.setStatus("dnd");
discordClient.user.setActivity("for server startup.",
{
Expand Down Expand Up @@ -321,7 +340,7 @@ function shutdown()

if (connectedToDiscord)
{
discordClient.channels.get(defaultChannel).send("```diff\n- Bot shutting down...```");
discordClient.channels.cache.get(defaultChannel).send("```diff\n- Bot shutting down...```");
console.log("Signing out of Discord...");
discordClient.user.setStatus("dnd");
discordClient.user.setActivity("for server startup.",
Expand Down
4 changes: 2 additions & 2 deletions DyscordBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Dyscord",
"version": "0.2.0",
"description": "Dyscord, a Dystopia - Discord bridge",
"main": "DiscordBot.js",
"main": "DyscordBot.js",
"homepage": "https://www.karlofduty.com",
"license": "GPL-3.0-or-later",
"private": true,
Expand All @@ -18,6 +18,6 @@
"url": "https://github.com/KarlOfDuty/Dyscord"
},
"dependencies": {
"discord.js": "^11.4.2"
"discord.js": "*"
}
}

0 comments on commit 96741ca

Please sign in to comment.