javascript - 字符串错误上的简单 Webhook 代码“shardCount”?
问题描述
我试图制作并开始学习使用 API 编写出价但我有这个非常烦人的错误......我的代码是
const Discord = require('discord.js')
const webhookID = '888151030620106792';
const webhookToken = 'token-here';
const webhook = new Discord.WebhookClient(webhookID, webhookToken);
webhook.send('I am here')
如果是,我会出错:
PS C:\Users\jonat\Desktop\Api Dev\Discord and Rest Api> node webhooks.js
C:\Users\jonat\Desktop\Api Dev\Discord and Rest Api\node_modules\discord.js\src\util\Util.js:336
given[key] = def[key];
^
TypeError: Cannot create property 'shardCount' on string 'zFutoKYe-OfZrfPdh0UE5yCk2wMOe-B84Xcs_Af6a76DXTx6bt3WB48qZwH-KvUriqtI'
at Function.mergeDefault (C:\Users\jonat\Desktop\Api Dev\Discord and Rest Api\node_modules\discord.js\src\util\Util.js:336:20)
at new BaseClient (C:\Users\jonat\Desktop\Api Dev\Discord and Rest Api\node_modules\discord.js\src\client\BaseClient.js:20:25)
at new WebhookClient (C:\Users\jonat\Desktop\Api Dev\Discord and Rest Api\node_modules\discord.js\src\client\WebhookClient.js:26:5)
at Object.<anonymous> (C:\Users\jonat\Desktop\Api Dev\Discord and Rest Api\webhooks.js:9:25)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47
当我这样做时,我得到了同样的错误:
const Discord = require('discord.js');
const webhook = new WebhookClient('888151030620106792', 'zFutoKYe-OfZrfPdh0UE5yCk2wMOe-B84Xcs_Af6a76DXTx6bt3WB48qZwH-KvUriqtI')
webhook.send('Hello World;)')`
解决方案
const discord = require('discord.js');
const data = {
id: 'idhere',
token: 'tokenhere'
}
const webhook = new discord.WebhookClient(data);
webhook.send('hello');
我今天也遇到了这个问题,但是通过将 webhook 数据作为对我有用的对象发送,希望这会有所帮助
推荐阅读
- javascript - 如何显示存储在 javascript 对象中的格式化 html 代码
- python-3.x - 有没有办法用 TypeError 异常缩短这个 json 代码?
- windows - 如果您在 C:/ 驱动器中运行 findstr 命令,它会执行多深?
- python - 我应该如何调查 Python 脚本在各种机器中的奇怪行为?
- angular - ngif 组件很快显示然后消失
- c# - 是否可以使用 VSTO 插件在 Outlook 阅读电子邮件中防止复制 (ctrl + c)?
- c++ - 隐式自动类型说明符
- button - 禁用/启用所有标签和文本字段,甚至一些按钮,直到用户单击复选框
- asp.net-mvc - 如何在 ASP.NET MVC 中设置默认值
- rust - 不遵守 Actix PayloadConfig 限制