我开始编写我的discord机器人,并且刚刚尝试添加一个特性,将特定的原始事件记录到特定的通道。我在Reddit和这个网站上看了无数遍,试图找到一个不被反对的方法,但没有运气。我希望我能在这个网站上回答。总而言之,我需要将消息发送到一个特定的通道。另一件事是从JSON文件中提取信息,如下所示:
info.json: {t: 'PRESCENCE_UPDATE,
{other_thing_i_want_to_get: 'blah blah blah'}}
如何以info.t.other_thing_i_want_to_get或类似的格式获取其他内容?
我建议创建一个json文件并导入它。
使用npm模块fs,您可以创建WriteFileStreams来更改存储在文件中的值
const info = require('./path_to_json/info.json');
您的json必须看起来像:
{t: 'PRESCENCE_UPDATE', other_thing_i_want_to_get: 'blah blah blah'}
有了这段代码,您可以使用info.other_thing_i_want_to_get获取它