javascript - 在事件中使用客户端与事件处理程序和 ...args | Discord.js@13
问题描述
我想client
在活动中使用,但我不知道如何在不移除的情况下将其交出... args
事件处理程序:
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
和事件模块:
module.exports = {
name: 'interactionCreate',
async execute(client,interaction) {
//... need client from code before here
},
};
解决方案
只需添加client
到参数!
if (event.once) {
client.once(event.name, (...args) => event.execute(client, ...args));
} else {
client.on(event.name, (...args) => event.execute(client, ...args));
}
推荐阅读
- java - Nginx反向代理后面的Docker容器中的Spring Boot不起作用
- python - 创建多节点套接字集群,其中每个节点与所有其他节点通信
- r - 执行 TukeyHSD 时出现未定义列错误
- c# - 在 ASP.NET Core 中实现下载大于 2gb 的大文件
- php - preg_match_all 查找循环分组这可能吗?
- sql - 在 MS Access 报告中水平显示数据
- mysql - 如何使用 INSERT INTO --- SELECT 和新的时间戳?
- android - 线程中的 KMM IncorrectDereferenceException
- sorting - 如何使用两个子字符串相等条件对字符串进行排序?
- excel - 我们如何从过滤器中进行选择,除了 excel 数据透视表中的最后一个或第一个选项