Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
djs-structure
Advanced tools
Readme
Advanced structure, algorithms, and tools for Discord.JS (v13 and up)
If you aren't planning on using message-based commands and will only use slash commands, you can create a bot like this
import {ManagedClient, Module, Command, IncomingCommand} from "djs-structure";
class MyCommand extends Command {
constructor() {
super("mycommand", "Description here", [
// any options here, follows application command option structure, this arg is optional
])
}
async incoming(i: IncomingCommand) {
await i.reply("Reply from my command");
}
}
class MyModule extends Module {
constructor() {
super("my-module")
}
load() {
this.registerCommand(new MyCommand());
}
}
class MyBot extends ManagedClient {
init() {
this.initStructure(new MyModule());
this.login("my-token");
}
}
const bot = new MyBot();
bot.init();
If you do this, commands, modules, and slash commands are all automatically managed for you. If you want to go more in depth, you can replicate the managed client in [ManagedClient](. /src/client/ManagedClient) and the typings will allow you to use it as long as it has the registerCommand and registerModule methods!
If you wanted to add message-based command support that uses the same codebase as your slash commands, there are built in methods for simulating them. You could do this (typescript):
import {Message} from "discord.js";
import {IncomingCommand} from "djs-structure";
this.on("messageCreate", async (msg) => {
// check if it starts with the prefix
if (msg.content.startsWith("!")) {
// remove prefix
let content = msg.content.replace(/^!/, "");
// match name
const nameMatches = content.match(/^[A-z0-9]/);
if (!nameMatches || nameMatches.length <= 0) return;
const cmd = nameMatches[0];
content = content.replace(new RegExp(`%${cmd} ?`))
// ^^^ removes command from content and optional space after
if (this.commands.has(cmd.toLowercase())) {
const command = this.commands.get(cmd.toLowercase()) as Command;
if (!command.opts.supportsMsg) return; // by default this is true
let deferredMessage: Message | undefined = undefined;
// only defer if really needs to be, without forcelong this will only apply to slash
// commands
if (command.opts.long && command.opts.forcelong) {
deferredMessage = await msg.reply("Processing...");
}
const incoming = new IncomingCommand({
type: "message",
client: this,
command,
message: msg,
content,
deferredMessage
});
try {
await inc.parseCommand(); // parses arguments into application command options
await command.incoming(incoming);
} catch (e) {
// something went wrong, tell the user
msg.reply(`${e}`);
} finally {
if (command.opts.isPublic === false) await msg.delete();
}
}
}
})
If you want to implement your own way to handle incoming commands and emit an incoming event to a command, see the bottom of ManagedClient
More will come in the future!
FAQs
Advanced structure, algorithms, and tools for Discord.JS (v13 and up)
The npm package djs-structure receives a total of 1 weekly downloads. As such, djs-structure popularity was classified as not popular.
We found that djs-structure demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.