Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The quick and easy Discord.js upgrade #350

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

steelskillet
Copy link
Contributor

updated discord.js to v14.14.1 (latest) and fixed any issues present with the plugins.

you will note few changes with plugins. this is because the major change that had to be done was making the embed part of a list which is handled in the base-plugin.

server-status had changes that needed to be made because it relied on the embedBuilder/Embed object, which has changed drastically, it now utilizes the json format which has had 0 changes from v12->v14.

Was quickly tested on Unnamed servers and all was working well.

@steelskillet
Copy link
Contributor Author

requires version change still

@steelskillet
Copy link
Contributor Author

steelskillet commented Mar 17, 2024

fix for discord-server-status.js, the activity type field wasn't changed to the proper input. set to custom activity so that it's easy to see the entire status text from the sidebar.
forgot to rename the commit message

@MartinezAye
Copy link

Have you got plugins to log to threads within channels?

@steelskillet
Copy link
Contributor Author

steelskillet commented Mar 17, 2024

yup, just tested it. threads are pretty much treated like channels from an API perspective from discord. so you just throw the thread ID in for where the channel ID is.
they won't make the threads on their own, you have to make them, but they do log to threads.

@werewolfboy13 werewolfboy13 added the Testing Required This requires testing before approval. label Mar 17, 2024
@werewolfboy13
Copy link
Collaborator

Adding flags, will need some QA on this so I can make sure its stable enough to make ready for public use.

@steelskillet
Copy link
Contributor Author

yup, currently running on all unnamed servers flawlessly so far.

@steelskillet
Copy link
Contributor Author

steelskillet commented Mar 22, 2024

potential changes to make so that plugins have a better chance of not needing changes.

  • parse the embed colors, discord.js seems to have changed what it likes for this.
  • mirror the messageCreate event to an event named message.

@steelskillet
Copy link
Contributor Author

side note that this PR fixes a known bug that causes squadjs/discord.js to crash when sending text in voice channels.

@magicoflolis
Copy link

@steelskillet So before in v12 you could await the login function which then resolves the whole Client class.

In v14 it is slightly different, after await connector.login() is resolved, the Client will not be completely ready, only once Events.ClientReady is emitted then the Client class is ready.

image

With current method:
image

In order to fix this we would need to wait until the Client is "ready" before returning the connector.

/squad-server/factory.js

await new Promise((resolve, reject) => {
	connector.once(Events.ClientReady, (readyClient) => {
	    Logger.verbose('SquadServerFactory', 1, `Ready! Logged in as ${readyClient.user.tag}`);
	    resolve();
	});
	connector.once(Events.Error, reject);
	connector.login(connectorConfig);
}).catch((ex) => {
	throw ex
});

Result:
image

The downside is the startup process takes slightly longer due to waiting for the client to fully be ready.

image

In addition to v14 , channels are cached in a Map so there is no need to await and fetch them.

/squad-server/plugins/discord-base-plugin.js

/** @type { import('discord.js').Client<true> } */
this.discordClient = this.options.discordClient;
this.channel = this.discordClient.channels.cache.get(this.options.channelID);

@werewolfboy13 werewolfboy13 self-assigned this May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing Required This requires testing before approval.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants