我想在命令中添加消息的作者。像这样: Hello World-@Author 我曾尝试单独这样做,但失败了,希望您能为我提供帮助。) 我真的不明白为什么它不起作用,我尝试了很多更改,但是在没有作者的情况下它仍然给我传达了信息
我当前的代码:
const Command = require('../structures/command.js');
const SubCommand = require('../structures/subcommand.js');
module.exports = class Say extends Command {
constructor(client) {
super(client);
this.name = "say";
this.subcommands = [new EmbedSay(client, this)];
}
run(message, args, commandLang, databases, lang) {
if (message.member.hasPermission('ADMINISTRATOR')) {
message.channel.send(args.join(' '));
message.delete();
} else {
var embed = this.client.getg1cuEmbed(message);
embed.setDescription(lang.missing_manageguild_permission);
embed.setColor(this.client.config.colors.error);
message.channel.send(embed);
}
}
}
class EmbedSay extends SubCommand {
constructor(client, parentCommand) {
super(client, parentCommand);
this.name = "embed";
this.aliases = ["--embed"];
}
run(message, args, commandLang, databases, lang) {
if (message.member.hasPermission('ADMINISTRATOR')) {
try {
var json = JSON.parse(args.join(' '));
} catch (e) {
var embed = this.client.getg1cuEmbed(message);
embed.setColor(this.client.config.colors.error);
embed.setTitle(commandLang.json_error_title);
embed.setDescription(commandLang.json_error_desc);
message.channel.send(embed);
return;
}
message.delete();
if (json.content) {
message.channel.send(json.content, json);
} else {
message.channel.send(json);
}
} else {
var embed = this.client.getg1cuEmbed(message);
embed.setDescription(lang.missing_manageguild_permission);
embed.setColor(this.client.config.colors.error);
message.channel.send(embed);
}
}
}
答案 0 :(得分:0)
简单地在discord.js中获得消息的作者:
获取ID:message.author.id
获取标签:message.author.tag
获取网址:message.author
或 '<@!' + message.author.id + '>'
答案 1 :(得分:-1)
我不是真的很喜欢discord.js,但我确实知道一件事,user.mention
始终有效,并且提到了键入命令的用户。 member.mention
也可以使用。
如果这不起作用,很抱歉导致您偏离轨道,但这也许会有所帮助:https://discord.js.org/#/docs/main/stable/general/welcome