首页 > 解决方案 > 使用 JavaScript,我如何能够创建一个从 PHP 文件调用以将键和属性添加到 JSON 文件的函数?

问题描述

所以我正在使用 Discord.JS 创建一个 Discord Bot,我有一个命令

 if(command === "addme") {
 //code here
 return message.reply(`Added ${message.author} to Database!`);
 };

如何让它从将键和属性添加到 JSON 文件的文件中调用 PHP 函数?

我被困在从哪里开始。我已经尝试了人们在此站点上发布的其他问题的解决方案,但我找不到任何可以解决我的问题。

谢谢,如果你能帮忙!

标签: javascriptphpjsonnode.jsdiscord

解决方案


这取决于你想在哪里打电话给你的php function

从表面上看,如果我没记错的话……似乎您不想与DiscordJS's API 进行交互,而不是custom PHP function?

  1. 客户端

    • 它是在浏览器,iOS还是Android上?- 根据您所处环境的选择,有几种不同的方法。
  2. 服务器端

    • 我假设您使用 JS 作为后端,您可以使用HTTP client类似的请求

简单的线条如

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.
});

就在你需要开始的地方,

干杯:)


推荐阅读