【发布时间】:2022-01-27 07:15:33
【问题描述】:
我怎样才能像这样创建一个命令 guildOnly? https://cdn.discordapp.com/attachments/824411059443204127/925437730895306802/unknown.png
这就是我的命令处理程序的样子
import { Command } from './@types'
let commands: Map<string, any> = new Map()
let aliases: Map<string, any> = new Map()
const commandFolder = fs.readdirSync(path.resolve(__dirname, `./commands`))
for (const folder of commandFolder) {
const commandFile = fs.readdirSync(path.resolve(__dirname, `./commands/${folder}`)).filter(file => file.endsWith('.ts'));
for (const file of commandFile) {
const cmd = require(`./commands/${folder}/${file}`) as Command;
console.log(`${cmd.name} in ${folder}`);
commands.set(cmd.name, cmd);
if (!cmd.aliases) continue;
if (cmd.aliases.length > 0) for (const alias of cmd.aliases) { console.log(`${alias} configed to ${cmd.name}`); aliases.set(alias, cmd); }
}
}
【问题讨论】:
-
您使用的是基于文本的命令,而不是较新的斜杠命令,对吧?
-
我还有一个斜杠命令处理程序``` let slashes: Discord.Collection
= new Discord.Collection(); client.on('ready', () => { fs.readdirSync( ${__dirname}/slash-commands).forEach((dir) => { fs.readdirSync(${__dirname}/slash-commands/${dir}).forEach(async (cmd) => { 常量文件= await import(${__dirname}/slash-commands/${dir}/${cmd}); await client.guilds.cache.get("875064681079898122")?.commands.create(file) await client.application?.commands.create(file); slashes.set(file.name , 文件) }) }) }) ```` -
if(cmd.guild && message.guild.id !== GUILD_ID) return;如果没有互动。 -
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
标签: node.js typescript discord.js