我正在尝试发出用于注册的命令,用法为$signup <TeamName> @user
。此命令应为执行命令的用户和@user(提到的人)提供“参与者”角色,并使用TeamName创建另一个角色并将其提供给他们。注册人数最多为32个小组(总共64个小组)。
我当前的命令是这个,它没有创建角色“ TeamName”,因为我真的不知道该怎么做。
client.on('message', async message => {
if (message.content.startsWith(prefix + "signup")) {
if (message.channel.id == '730099836451422331') {
let teamMate = message.mentions.members.first()
const teamName = message.content.slice(prefix.length + 7).split(/ +/)
let testRole = message.guild.roles.cache.find(role => role.name == "Participant")
let testChannel = message.guild.channels.cache.find(channel => channel.name == "signup")
let guild = await message.guild.members.fetch();
let memberCount = testRole.members.size;
if(memberCount === 64) return message.channel.send("All spots have been filled. Thank you.")
if(!teamMate) return message.channel.send("Please mention your teammate! `$signup @user`")
if (message.member.roles.cache.some(role => role.name === 'Participant')) return message.channel.send("You already have the role.")
if (teamMate.roles.cache.some(role => role.name === 'Participant')) return message.channel.send("That teammate already has the role! Pick someone else!")
teamMate.roles.add(testRole)
message.member.roles.add(testRole)
message.guild.roles.create({data:{
name: teamName
}})
答案 0 :(得分:1)
现在您有了->
let teamMate = message.mentions.members.first()
const teamName = message.content.slice(prefix.length + 7).split(/ +/)
您可以更改
const msgArr = message.content.split(' ');
const arg = msgArr.slice(number).filter(val => val !== '')
const teamName = arg.join(' ')
数字是您要删除的args数量,例如您有注册用户 团队名称,因此您需要删除2个参数,您将获得其余内容作为团队的主题