feat: more clear error for access message or interaction

This commit is contained in:
Jacob Nguyen
2022-06-05 11:17:59 -05:00
parent 6429085650
commit 18d07d6e2d
2 changed files with 4 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ import type {
import { None, Option, Some } from 'ts-results';
import type { Nullish } from '../../types/handler';
import { ExternallyUsed } from '../utilities/externallyUsed';
import { SernError } from './errors';
function firstSome<T>(...args: Option<T>[]): Nullish<T> {
for (const op of args) {
@@ -43,7 +44,7 @@ export default class Context {
*/
@ExternallyUsed
public get message() {
return this.oMsg.unwrap();
return this.oMsg.expect(SernError.MismatchEvent);
}
/**
* Getting the ChatInputCommandInteraction object. Crashes if module type is
@@ -52,7 +53,7 @@ export default class Context {
*/
@ExternallyUsed
public get interaction() {
return this.oInterac.unwrap();
return this.oInterac.expect(SernError.MismatchEvent);
}
@ExternallyUsed

View File

@@ -4,4 +4,5 @@ export enum SernError {
MismatchModule = `A module type mismatched with event emitted!`,
NotSupportedInteraction = `This interaction is not supported.`,
PluginFailure = `A plugin failed to call controller.next()`,
MismatchEvent = `You cannot use message when an interaction fired or vice versa`,
}