javascript - 如何为整个文件制作 const?
问题描述
有什么方法可以为整个文件制作 const 吗?比如获取categoryId const,这样就可以用于message.channel.send(categoryId)
module.exports = {
name: 'new',
description: "Vytvoří novou sekci pro zákazníka",
async execute(message, args, Discord, client, chalk){
message.guild.channels.create(` | ${args[0]}`, { type: 'category' })
.then(category => {const categoryId = (category.id)})
message.channel.send(categoryId)
}
}
解决方案
是的,只需在文件顶部声明即可。但是,在您的情况下,let
将比 更合适const
,因为您必须在创建时为其分配一个值const
,因此您的解决方案将如下所示:
let categoryID;
module.exports = {
name: 'new',
description: "Vytvoří novou sekci pro zákazníka",
async execute(message, args, Discord, client, chalk){
message.guild.channels.create(` | ${args[0]}`, { type: 'category' })
.then(category => categoryID = category.id)
message.channel.send(categoryID)
}
}
推荐阅读
- c# - SVGImage 在 Mapbox 的 Unity SDK 中导致编译器错误
- sql - 奇怪的错误:关系
不存在 - json - 解析没有键名的 JSON 以检索列
- javascript - 将具有数组值的对象键转换为查询字符串
- laravel - 已解决 Laravel 网站对 GET 请求返回“错误 404”
- reactjs - 当 react-router-dom 链接与材料 ui ListItem onClick 一起使用时,反应状态未更新
- python - Pandas Groupby 剧情布局
- python - 在 matplotlib 中创建动态脚注文本
- node.js - NodeJs项目如何使用户输入未经处理?
- angular - 单元测试角度和茉莉花