【发布时间】:2021-11-06 12:16:25
【问题描述】:
我一直在遵循一些不同的指南来编写一个简单的不和谐机器人。一切正常,除了我无法让它发送图像。我看过这些以前的问题12,但他们的解决方案对我不起作用。这是我的代码:
const {Client, Intents} = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '?';
client.once('ready', () => {
console.log("Dog is online!");
});
client.on('messageCreate', message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping') {
message.channel.send('pong!');
}
else if (command === 'bark') {
message.channel.send('bark bark bark grrrr...')
}
else if(command === 'nick') {
message.channel.send('grrr...');
}
else if (command === 'pic') {
message.channel.send("little dog", {files: ["https://i.imgur.com/xxXXXxx.jpeg"] });
}
});
//must be last line
client.login('');
我的客户端登录在我的编辑器中,只是不在这里分享。 “pic”命令不起作用。它显示“小狗”文本,但不发送图像。我使用 imgur 的唯一原因是我不确定您是否可以发送本地图像;如果有人知道使用本地文件的解决方案,我会接受。
【问题讨论】:
标签: javascript node.js discord.js