javascript - 使用 JavaScript,我如何能够创建一个从 PHP 文件调用以将键和属性添加到 JSON 文件的函数?
问题描述
所以我正在使用 Discord.JS 创建一个 Discord Bot,我有一个命令
if(command === "addme") {
//code here
return message.reply(`Added ${message.author} to Database!`);
};
如何让它从将键和属性添加到 JSON 文件的文件中调用 PHP 函数?
我被困在从哪里开始。我已经尝试了人们在此站点上发布的其他问题的解决方案,但我找不到任何可以解决我的问题。
谢谢,如果你能帮忙!
解决方案
这取决于你想在哪里打电话给你的php function
,
从表面上看,如果我没记错的话……似乎您不想与DiscordJS
's API 进行交互,而不是custom PHP function
?
客户端
- 它是在浏览器,iOS还是Android上?- 根据您所处环境的选择,有几种不同的方法。
服务器端
- 我假设您使用 JS 作为后端,您可以使用
HTTP client
类似的请求
- 我假设您使用 JS 作为后端,您可以使用
简单的线条如
var request = require('request');
request('https://saficloud.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the SafiCloud homepage.
});
就在你需要开始的地方,
干杯:)
推荐阅读
- angular - 我在运行角度材料时遇到问题
- ios - 在编辑模式下仍可选择单元格
- webpack - 使用 webpack 定义插件在编译时定义导入路径
- react-native - 如何修复 React-Native 错误“无法解压缩 gradle-5.4.1-all.zip”
- python - 循环遍历具有列标题的行
- graphql - GraphQL Dataloader - 带有 load() 函数的全局变量
- tensorflow - 无法在我的 Colab 托管运行时中使用 tensorflow.keras.layers.CuDNNLSTM 或 keras.layers.CuDNNLSTM
- mysql - aws mysql 数据库(Amazon RDS)还是 mongodb?
- ruby-on-rails - 使用管理时添加请求参数时出现不允许的参数错误
- python - 我怎样才能使列表中的每个项目延迟发生?