message.channel.sendMessage(text).attachments
["",{url:"http://openweathermap.org/img/w/"+icon+".png" }];
Run Code Online (Sandbox Code Playgroud)
我做了一些机器人,使用node-js(discord.js)我想发送带图片的消息(没有URL)所以,我在文档中找到了功能附件.但是,我在消息(文本)和处理中添加了一些图片,但在控制台中,"无法读取属性'#<Object>'未定义"我应该怎么做才能解决这个问题?
我一直在遵循一些不同的指南来编写一个简单的不和谐机器人。一切正常,除了我无法让它发送图像。我已经看过这些之前的问题1 2,但他们的解决方案对我不起作用。这是我的代码:
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: …Run Code Online (Sandbox Code Playgroud)