S-IAF

Sapphire - Imagine a framework

Welcome to the Sapphire Discord server! The next-gen object-oriented Discord.js bot framework can be found here.

Join Server

Community questions

CChillihero3/31/2023

How to get infos about the current task?

I want to log things like taskid etc. what infos are there to work with and how do I get them inside of my task?
Yyusof3/31/2023

How can i start using bulkOverwrite

I was just curious on how I could start using BulkOverwrite to override slash commands?
JJesse3/30/2023

Adding preconditions to a slash command?

Is there a way to add a precondition to an application command? I'm not sure if it works the same as the old chat commands or if I would have to hardcode them into each command.
Ss4g3/30/2023

mongoose listener not working

im trying to setup a mongoose listener for the 'open' event however saphire doesnt seem to catch it my best guess is i didnt specify the right emitter as my other listeners work here is a screenshot
Image
Image
AAkanixon3/30/2023

TypeError: channel.isTextBased is not a function

I have a problem with Interactions:
Since yesterday evening every button interaction results in an error as follows
/home/developer/Wishbot/node_modules/discord.js/src/client/actions/InteractionCreate.js:50
        if (channel && !channel.isTextBased()) return;
                                ^

TypeError: channel.isTextBased is not a function
    at InteractionCreateAction.handle (/home/developer/Wishbot/node_modules/discord.js/src/client/actions/InteractionCreate.js:50:33)
    at module.exports [as INTERACTION_CREATE] (/home/developer/Wishbot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (/home/developer/Wishbot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31)
    at WebSocketShard.onPacket (/home/developer/Wishbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:489:22)
    at WebSocketShard.onMessage (/home/developer/Wishbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:328:10)
    at callListener (/home/developer/Wishbot/node_modules/ws/lib/event-target.js:290:14)
    at WebSocket.onMessage (/home/developer/Wishbot/node_modules/ws/lib/event-target.js:209:9)
    at WebSocket.emit (node:events:512:28)
    at Receiver.receiverOnMessage (/home/developer/Wishbot/node_modules/ws/lib/websocket.js:1180:20)
    at Receiver.emit (node:events:512:28)
MMoons3/30/2023

Can not resolve dependency sapphire

Hello, after todays NODE JS update, im having an issue with sapphire dependency, would you be able to advise me? thank you.
Image
Image
Ccosigyn3/29/2023

UserError listener not catching all errors

I am running an imported function in my command, and calling UserError in this file and when I do, it is not caught by the listener, and my bot crashes.

Error Source: https://github.com/cosigyn/Clanware-V3/blob/master/src/mods.mjs#L229
Command: https://github.com/cosigyn/Clanware-V3/blob/master/src/commands/general/affiliate.mjs
GGabriel.3/29/2023

How to get message args ?

Like i have command +mark 123, how i can get the 123
SShowCast3/28/2023

API Placeholder in Route

I didn't found it in the docs. Is there any way to get a placeholder into a route like in express with /routename/:id so I can use it to get the resource with the respective id?
MMantaro3/28/2023

TypeError piace.aliases is not iterable

Good afternoon, I mixed such a strange code as best I could. My task was to add a button to the message with a built-in embed, but it's not clear why I get an error in the console, please give me an answer what I did wrong :). Code and error below.

const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, } = require("@discordjs/builders")
const { Command, Piece, InteractionHandlerTypes } = require('@sapphire/framework');
const { ButtonStyle, InteractionType } = require("discord.js");

class Embed extends Command {
constructor(ctx, context, options) {
super(ctx, context, { ...options,
InteractionHandlerType: InteractionHandlerTypes.Button
});
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder.setName('rules').setDescription('description')
);
}
async chatInputRun(interaction,client) {
const button = new ButtonBuilder()
.setCustomId("rulesrp")
.setLabel(label)
.setStyle(ButtonStyle.Primary);


const embed = new EmbedBuilder()
.setTitle('title')
.setDescription(descriptiom)
.setTimestamp()
const embed2 = new EmbedBuilder()
.setTitle('title')
.setDescription(desciption)
.setTimestamp()
const embed3 = new EmbedBuilder()
.setTitle('title')
.setDescription(description)


interaction.channel.send({ embeds: [embed,embed2,embed3]}, {components: [ActionRowBuilder(),addComponents(button)]})
}
}
module.exports = {
Embed, ActionRowBuilder, ButtonBuilder
}
D:Файлы\Project 1\node_modules@sapphire\pieces\dist\lib\structures\AliasStore.js:58
for (const key of piece.aliases) {
^
Image
Image
SShowCast3/26/2023

API Client with SSL?

Hey guys,

currently I am trying to make the switch from an custom express API to the API plugin. Is there a way to let the plugin consume an ssl cert and open a https server?

Greetings
MMRDGH28213/26/2023

Context Menu Command and Subcommand cannot be in same extended class?

I have a slash command which is an extended Subcommand called give-role with two subcommands - one & multi.

The file name is give-role.ts

Now I also want a Context Menu command named Give Role within same give-role.ts

I can register both slash command & context menu command, but cannot provide contextMenuRun() within same give-role class.

Any solution(s)?
Ccosigyn3/25/2023

UserErrors not being caught by listener - bot is crashing

messageCommandError.mjs
import { Events, Listener } from "@sapphire/framework";
import { send } from "@sapphire/plugin-editable-commands";
import { EmbedBuilder } from "discord.js";

export class UserEvent extends Listener {
  constructor(context, options) {
    super(context, {
      ...options,
      once: false,
      event: Events.MessageCommandError,
      name: "messageCommandError",
    });
  }

  async run({ context, message: content }, { message: msg }) {
    // `context: { silent: true }` should make UserError silent:
    // Use cases for this are for example permissions error when running the `eval` command.
    if (Reflect.get(Object(context), "silent")) return;

    const embed = new EmbedBuilder()
      .setTitle("Command Failed")
      .setDescription(content)
      .setColor("Red")
      .setTimestamp();

    return send(msg, {
      embeds: [embed],
      allowedMentions: { users: [msg.author.id], roles: [] },
    });
  }
}
XXenfo3/25/2023

Subcommand isn't running

When the subcommand is run in Discord, it times out. I've added a log to the beginning of the method but it isn't triggered. Normal commands work fine.

@ApplyOptions<Subcommand.Options>({
  name: 'blacklist',
  description: 'Blacklist users or guilds from using the bot.',
  preconditions: ['OwnerOnly'],
  subcommands: [
    {
      name: 'user',
      chatInputRun: 'chatInputUser'
    }
  ]
})
export class BlacklistCommand extends Subcommand {
  public override registerApplicationCommands(
    registry: ChatInputCommand.Registry
  ) {
    registry.registerChatInputCommand(
      (builder) =>
        builder
          .setName(this.name)
          .setDescription(this.description)
          .addSubcommand((command) =>
            command
              .setName('user')
              .setDescription('Blacklist a user from using the bot.')
              .addUserOption((option) =>
                option
                  .setName('user')
                  .setDescription('The user to blacklist.')
                  .setRequired(true)
              )
          ),
      {
        guildIds: config.testGuilds
      }
    );
  }

  public async chatInputUser(
    interaction: Subcommand.ChatInputCommandInteraction
  ) {
ZZusor3/23/2023

How to properly handle UserErrors?

I'm using the official sapphire template and want to throw a UserError inside a context menu command.
How do I correctly handle the error and send a message to the user?
I saw contextMenuCommandDenied.ts and thought that would handle it but I don't get a response and the error is shown in the logs.
CCata3/22/2023

Can I set different requiredUserPermissions for each subcommand?

Just wondering if this is possible, and how. Thanks
Kkyle133/21/2023

Handling BulkOverwrite Registry Errors

When I encounter this error
[ERROR] ApplicationCommandRegistries(BulkOverwrite) Failed to overwrite guild application commands for guild 1********* DiscordAPIError[50001]: Missing Access


I want to be able to capture this error and take an action. In this case update my record of guilds to remove the inaccessible guild.

I've tried to capture the errors using the error event listener as well as one on commandApplicationCommandRegistryError however neither seems to be called when this error occurs. What is the recommended way to listen for these BulkOverwrite error events?

Example listeners which are never called:
import { ApplyOptions } from '@sapphire/decorators';
import { Listener, Events, Command } from '@sapphire/framework';

@ApplyOptions<Listener.Options>({
  event: Events.CommandApplicationCommandRegistryError,
})
export class ApplicationRegistryError extends Listener<
  typeof Events.CommandApplicationCommandRegistryError
> {
  public run(error: unknown, command: Command) {
    console.error('caught registry error');
    console.error(error);
  }
}


import { Events, Listener } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';


@ApplyOptions<Listener.Options>({
  event: Events.Error,
})
export class ErrorListener extends Listener {
  public run(error: Error) {
    console.error('captured error');
    console.error(error);
  }
}
Sshadowolf3/20/2023

Events for Voice

How can I do something like the following but for voice?

import { Listener } from '@sapphire/framework';

export class VoiceStateUpdateListener extends Listener {
  constructor(context, options) {
    super(context, {
      ...options,
      once: false,
      event: 'voiceStateUpdate'
    });
  }

  async run(oldState, newState) {
    console.log(newState);
  }
}
Ttk3/20/2023

How do I use autocompleteRun on subcommands?

^ As the title says. I can't seem to figure out how subcommands can have autocompleteRun implemented. I'm not too worried about duplicates, since there is only one subcommand that uses autocomplete.