Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

discord.js - So i'm trying to make a discord bot that can send random pictures in a js format but i have no idea how to

if(command === 'example'){

client.commands.get('exaple').execute(message, args);

message.channel.send('https://i.redd.it/6nkyme7ayi631.jpg');

module.exports = {

name: 'example',

description: "this is a test command",

execute(message, args, Discord){
    message.channel.send('https://i.redd.it/6nkyme7ayi631.jpg');
}

}

question from:https://stackoverflow.com/questions/65944798/so-im-trying-to-make-a-discord-bot-that-can-send-random-pictures-in-a-js-format

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Create an array of image URLs and then pick a random item from the array to send

// Example using numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]

// module.exports etc
const randomNumber = numbers[Math.floor(Math.random() * numbers.length)]

// send the random number/url
// I'm using console.log() to avoid an error
console.log(randomNumber)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...