Open Satont opened 3 years ago
https://github.com/OwenCalvin/discord.ts/blob/slash/examples/guards/guards/Say.ts
check above example for proper usage and let us know if issue persist
Changed my code to
export const SlashCommandPermission = (permissions: PermissionResolvable[] | PermissionResolvable) => {
const guard: GuardFunction<ArgsOf<'message'> | CommandInteraction> = async (data, client, next, guardDatas: GuardDatas) => {
console.log(data instanceof CommandInteraction);
if (data instanceof CommandInteraction) {
const perms = Array.isArray(permissions) ? permissions : [permissions];
const guildMember = data.guild.members.cache.get(data.member.user.id);
const hasPermissions = perms.every((perm) => guildMember.permissions.has(perm));
if (!hasPermissions) {
guardDatas.error = 'You have no access to this command';
data.reply({ embeds: [noPermissionError] });
} else {
await next();
}
} else {
await next();
}
};
return guard;
};
Now i has no errors, but seems like nothing responsed to me in discord. I mean when i using some slash command, then it's failed.
It's even not logging does it's instance of interaction or not.
Command is now more simple:
@Slash('add')
async add(
@Option('channelId', { description: 'id of the channel for listening on join', required: true })
channelId: string,
interaction: CommandInteraction,
) {
interaction.reply('Test');
}
Btw, just copied example of Say guard, same behavior.
Make you are using this PR OwenCalvin/discord.ts/pull/62
and try this
export function ExampleGaurd(): GuardFunction {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const guard: GuardFunction<ArgsOf<"interaction">> = async (interaction, client, next, _guardDatas: string[]) => {
console.log(interaction instanceof CommandInteraction);
await next();
};
return guard;
}
@Discord()
@Guild(yourguild)
@Guard(ExampleGaurd())
export abstract class example {
@Slash("testguard", { description: "test guard" })
async testguard(interaction: CommandInteraction) {
await interaction.reply('guard is working');
return;
}
}
this example, has been tested right before this comment and working okay
Sadly, but not working for me.
Am i executing interactions correctly?
@On('interaction')
onMessage([interaction]: ArgsOf<'interaction'>, client: Client) {
info(`Interaction comed: ${interaction.type}`);
client.executeInteraction(interaction);
}
it's okay but you can log each steps, that all are executing correctly
btw interaction event has been rename to interactionCreate
and test your function without guard, that it's being executed.
btw interaction event has been rename to interactionCreate
Yea i know, and i see deprecation warning. But it missed typings on your branch and has only 'interaction' for me.
But everything like botid
is here, so i installed your branch correctly, right?
yes, log each steps that all are executing for debug
Ok, i just checked, interaction is comed, but not executed.
@Discord()
abstract class AppDiscord {
@On('interaction')
onMessage([interaction]: ArgsOf<'interaction'>, client: Client) {
info(`Interaction comed: ${interaction.type}`);
client.executeInteraction(interaction);
}
}
@Discord()
@Group('channels', 'Add or remove channel to bot watching list')
//@Guard(SlashCommandPermission('MANAGE_CHANNELS'))
export abstract class AppDiscord {
@Slash('add')
//@Guard(ExampleGaurd())
async add(
@Option('channelId', { description: 'id of the channel for listening on join', required: true })
channelId: string,
interaction: CommandInteraction,
) {
interaction.reply('test');
}
But nothing returned from bot.
you can pull new updates, I have added warning in console if a unknown interaction called
and to resolve your issue, create a test repo to produce bug. I will verify the issue in your repo.
const testMe: GuardFunction<CommandInteraction> = async (messageOrCommand, client, next, nextObj) => {
console.log("text");
await next();
};
check out this example https://github.com/oceanroleplay/discord.ts/blob/slash/examples/guards/guards/NotBot.ts from @AndyClausen
Congratulations! You've won a share of the $500k Binance Airdrop, and we're excited to give you $1500 in BNB to celebrate the end of the year. Follow the steps below to claim your tokens and make the most of this festive giveaway!
Don't miss out on your $1500 in BNB! Act now to secure your tokens.
Winners: @a2393439531, @jaewanLee, @kozo-cz, @chohankyun, @jaxonly, @YanzheL, @robbienohra, @happyhunter7, @xlucas, @markzhan, @Jinksi, @1549002514, @bfriel, @kongxun, @akshaydeshraj, @edangelion, @Mandey4172, @glauberramos, @shawkhawk, @huyhoang21997, @gino2010, @cchudant, @martapastor, @logig, @decadeofdata, @filimo, @sonnyit, @AltanS, @slackmage, @aur3l14no, @jotave42, @derek-palmer, @fars, @Corual, @kevoj, @KunoWA, @withu2018, @jollen, @jspittman, @adriennickson, @kblockdev, @tagamma, @scsfwgy, @xFvl, @bingyue, @cqamber, @reza35, @peeterburger, @AkselsLedins, @fengyunxiren
SlashCommandPermission.ts
Some controller: