[英]Discord.js image attachment
const { Client, Intents, MessageAttachment, Message } = require('discord.js');
const client = new Client({intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_PRESENCES", "GUILD_MEMBERS"]});
client.once('ready', () => {
console.log('In sfarsit joc DnD. Ssssssp.');
});
let x = 1;
client.on('message', msg =>
{
if (msg.content === "+help")
{
let msg1 = "You should know how to use me by now. Sssssssp. Times you were unworthy: ";
let msg2 = x.toString();
let msgf = msg1.concat(msg2);
x++;
msg.reply(msgf);
}
name = ["Triceps","Babuska","Dero","Special","Radw","Pucin","Eclipsentiu","Eugen","Tugen","Elgen","Ha Ha Bitch","Helium", "Saradin", "Chevrolet", "Gogo", "Cactus", "Sarkofag", "Guru", "Trubius", "Storyline", "Giorgio", "Wiggler", "Wig", "Stetoskop", "Tracu", "Mizil", "Trafalet", "Stepmom", "Yridim", "Soul","Lyfjaberg","Netflix","Gugutza","Rakshasa","Trubilion","Sufftard","Panu","Radulescu","Infatuated","Sex'n'Fund","Tuc","Streche","Nebanuit","Bust","Ecologie","Surf","Bag","0110","Pork","Fork","Redbuff"];
let no_changed = 0;
if (msg.content === "+exhale_the_truth")
{
if (Math.random() <= 0.05)
{
msg.reply("No. I don't think I will. Sssssssp.");
return;
}
msg.reply("Look what you made me do. Sssssssp.");
msg.guild.members.cache.forEach((a) => {
if (!a.permissions.has("ADMINISTRATOR"))
{
do {
nick = "";
if (Math.random() <= 0.08)
nick = "El ";
nick = nick + name[Math.floor(Math.random() * name.length)] + ' ' + name[Math.floor(Math.random() * name.length)] + ' ';
if (Math.random() <= 0.02)
nick = nick + "d'";
else
if (Math.random() <= 0.001)
nick = nick + "von";
nick = nick + name[Math.floor(Math.random() * name.length)];
}
while (nick.length > 32)
a.setNickname(nick);
console.log(nick);
no_changed++;
}
});
console.log(no_changed);
}
if (msg.content === "+DnD") {
var attc = new MessageAttachment('https://upload.wikimedia.org/wikipedia/commons/f/ff/Stefan_Banica_Jr.jpg');
msg.reply(attc);
}
});
client.login('token');
在
if (msg.content === "+DnD") {
var attc = new MessageAttachment('https://upload.wikimedia.org/wikipedia/commons/f/ff/Stefan_Banica_Jr.jpg');
msg.reply(attc);
}
顯然,這試圖發送一條空消息。 我只想附上一張圖片。 它也可能是來自我的計算機的路徑,我真的不認為我關心它是如何提供的,或者在實現方面存在差異。 Discord.js v13 順便說一句。 此外,我更喜歡一個非常簡單的解決方案,如果可能的話,不要使用太多復雜的概念。 顯然任何事情都會做。
使用messagw.reply({files: [attc]})
我建議使用 messageCreate 事件而不是 message
回復為空的原因是 Message.reply() 沒有接受 MessageAttachement。 它需要字符串、MessagePayload 或 ReplyMessageOptions。
您必須構建一個帶有附加文件的MessagePayload 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.