duscird.js 获取相关用户的名称
duscird.js get the name of the user involved
我有一个命令,其中一个用户虚拟地亲吻另一个用户
输出是一条消息@User1 kissed @User2
但我想要的不是用户标签,而是只写了名字,这样就 user1 kissed user2
理论上,一切都应该像这样工作
`**${message.author.username}** kissed **${userToKiss.username}**`
但是如果定义了 message.author
的名称,那么 userToKiss
就有 none,我最终得到这个
user1 kissed undefined
如何获取第二个用户的姓名?
const { Command } = require('discord.js-commando');
const Discord = require('discord.js');
module.exports = class KissCommand extends Command {
constructor(client) {
super(client, {
name: 'kiss',
memberName: 'kiss',
group: 'reywl',
description: 'Kiss the mentioned user',
guildOnly: true,
args: [
{
key: 'userToKiss',
prompt: 'Please select the member you want to kiss.',
type: 'member',
default: 'isempty',
wait: 0.0001
}
]
});
}
run(message, { userToKiss }) {
if (userToKiss == 'isempty') {
return message.channel.send('Please select the member you want to kiss.')}
if (userToKiss.id == message.author.id) {
return message.channel.send('You cant kiss yourself!');
}
else {
const embed = new Discord.MessageEmbed()
.setDescription(`**${message.author}** kissed **${userToKiss}**`)
message.channel.send(embed)
}
setTimeout(() => message.delete(), 1000)
}};
这是它的工作原理
const kissed = await message.guild.members.fetch(userToKiss.id);
${kissed.user.username}
为了深入解释你的工作,为此你需要先对成员进行编码,我们总是对member
和author
进行编码
Author 是作者本身,member 是您要呼叫的会员
我不知道 commando
和普通命令处理程序是否相同,但这是您想要的代码。
const member = message.mentions.members.first() //this is the way how you ping a member
${member.user.username} //the word user is the user member
作者只能这样做
${message.author.username}
您还可以使用成员的 ID 来 ping 一个成员
const member = message.guild.members.cache.get(args[0])
${member.user.username}
所以主要输出是
${message.author.username} kissed ${member.user.username}
我有一个命令,其中一个用户虚拟地亲吻另一个用户
输出是一条消息@User1 kissed @User2
但我想要的不是用户标签,而是只写了名字,这样就 user1 kissed user2
理论上,一切都应该像这样工作
`**${message.author.username}** kissed **${userToKiss.username}**`
但是如果定义了 message.author
的名称,那么 userToKiss
就有 none,我最终得到这个
user1 kissed undefined
如何获取第二个用户的姓名?
const { Command } = require('discord.js-commando');
const Discord = require('discord.js');
module.exports = class KissCommand extends Command {
constructor(client) {
super(client, {
name: 'kiss',
memberName: 'kiss',
group: 'reywl',
description: 'Kiss the mentioned user',
guildOnly: true,
args: [
{
key: 'userToKiss',
prompt: 'Please select the member you want to kiss.',
type: 'member',
default: 'isempty',
wait: 0.0001
}
]
});
}
run(message, { userToKiss }) {
if (userToKiss == 'isempty') {
return message.channel.send('Please select the member you want to kiss.')}
if (userToKiss.id == message.author.id) {
return message.channel.send('You cant kiss yourself!');
}
else {
const embed = new Discord.MessageEmbed()
.setDescription(`**${message.author}** kissed **${userToKiss}**`)
message.channel.send(embed)
}
setTimeout(() => message.delete(), 1000)
}};
这是它的工作原理
const kissed = await message.guild.members.fetch(userToKiss.id);
${kissed.user.username}
为了深入解释你的工作,为此你需要先对成员进行编码,我们总是对member
和author
Author 是作者本身,member 是您要呼叫的会员
我不知道 commando
和普通命令处理程序是否相同,但这是您想要的代码。
const member = message.mentions.members.first() //this is the way how you ping a member
${member.user.username} //the word user is the user member
作者只能这样做
${message.author.username}
您还可以使用成员的 ID 来 ping 一个成员
const member = message.guild.members.cache.get(args[0])
${member.user.username}
所以主要输出是
${message.author.username} kissed ${member.user.username}