I want to make the bot write to the BOT through the mention and through the ID .
Now it only works via ID
client.on("message", async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(" ");
const command = args.shift().toLowerCase();
const target = message.mentions.members.first() || message.guild.members.cache.get(args[0])
const { guild } = message;
const { name, region, memberCount, owner, afkTimeout } = guild;
const icon = guild.iconURL();
const User = client.users.cache.get(`${args[0]}`);
const time = args.slice(1).join(" ");
const reason = args.slice(2).join(" ");
if (command === "mute") {
client.users.fetch(args[0]).then((target) => {
target.send({
embed: {
title: `${User.username}`,
description: `**Miderator:** ${message.author} \n**Time:** ${args[1]} \n**Reason:** ${reason}`,
thumbnail: {
url: `${User.avatarURL()}`,
},
},
});
}); }});
You can do like
let person = message.mentions.users.first().id || args[0]
client.users.fetch(person).then(target => {
target.send({
embed: {
title: `${User.username}`,
description: `**Miderator:** ${message.author} \n**Time:** ${args[1]} \n**Reason:** ${reason}`,
thumbnail: {
url: `${User.avatarURL()}`,
},
},
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.