每个命令都有单独的文件夹。我将它们连接到main.js-这是我的GIF文件夹。
module.exports = {
name: 'gif',
description: "this is a gif!",
execute(message, args){
if (message.content === "-gif") { // checks if the message says "?random"
const number = Math.random(); // generates a random number
message.channel.send(number.toString()); // sends a message to the channel with the number
}
}
}
现在它会生成随机数。我希望它生成随机GIF(但是我想通过链接添加它从中选择的所有随机GIF)。
答案 0 :(得分:0)
定义不一致
const Discord = require('discord.js');
const client = Discord.Client();
添加消息事件监听器
client.on('message', message => {
//code goes here
}
从数组生成随机链接
const Discord = require('discord.js'); // defining the discord.js module
const client = Discord.Client(); //defining the bots client
client.on('message', message => { //a message event listener
if (message.content.toLowerCase().startsWith('-gif') { // checking if the message is equal to "-gif"
var gifs = ['linkToGif', 'linkToAnotherGif', 'etc'] //creating your array
var response = Math.floor(Math.random * gifs.length); //getting a random number from the array
message.channel.send(gifs[response] //sending the random link from the array
}
client.login('yourToken')