我正在关注如何制作不和谐机器人的本教程,一切正常,直到 33:32 他添加了我已经安装 giphy sdk/api 的 giphy 东西,创建了一个应用程序,但在他做出搜索声明后,他说你可以控制台记录它,所以我这样做了,并且有一些 gif 结果出来,在我的控制台上返回 undefined(我不知道为什么),然后他添加了一些数学内容,我也这样做了,然后在他添加的地方消息传递部分,他还添加了此代码files:[responseFinal.images.fixed_height.url]
,然后在我的控制台上返回了此代码
(node:3136) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'images' of undefined
at D:\Discord bots\Oboto v2.0\index.js:24:61
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:3136) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3136) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
这让我感到困惑,然后我选择了一种替代方法,而不是giphy.search
使用
giphy.random
相同的参数,删除了数学内容和console.log(response)
响应,并猜测它实际上给了我一个 gif !(当然在控制台中)然后我实现了我的files:[]
声明 aaaa 并且它返回了相同的东西(cannot read property 'images' of undefined
)我对 discord.js 和 javascript 也有点新,这也是我的整个代码,
const Discord = require('discord.js');
const { prefix, token, giphyToken } = require('./config.json');
const client = new Discord.Client();
var GphApiClient = require('giphy-js-sdk-core')
giphy = GphApiClient(giphyToken)
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])){
if (message.content.startsWith(`${prefix}kick`)) {
let member = message.mentions.members.first();
member.kick().then((member) =>{
giphy.random('gifs', {'q':'fail'})
.then((response) => {
console.log(response);
message.channel.send(":wave:",{files:[response.images.fixed_height.url]});
})
})
}
}
})
client.login(token);