我有一个命令,检查人员是否存在,然后检查人员是否在组中,然后提升人员。 该命令正在运行,并且正在提升他们,但是当我键入提升某人时,它会显示以下消息:
它也找不到等级的名称,并将其替换为undefined
。
这是我的代码:
import * as Discord from "discord.js";
import { IBotCommand } from "../api";
import * as ConfigFile from "../config";
let express = require("express");
let roblox = require('noblox.js');
export default class Promote implements IBotCommand {
private readonly _command = "promote";
help(): string {
return "Promote members in the Roblox group."
}
isThisCommand(command: string): boolean {
return command === this._command;
}
async runCommand(args: string[], msgObject: Discord.Message, client: Discord.Client): Promise<void> {
if (!msgObject.member.roles.find("name", "Council")) {
msgObject.channel.send(`Nice try ${msgObject.author.username} but you don't have permission to promote members!`)
.catch(console.error);
return;
}
let groupId = 5293276;
let maximumRank = ConfigFile.config.maximum_rank
let username = args[0]
if (username) {
msgObject.channel.send(`Checking ROBLOX for ${username}`)
roblox.getIdFromUsername(username)
.then(function (id: any) {
roblox.getRankInGroup(groupId, id)
.then(function (rank: number) {
if (maximumRank <= rank) {
msgObject.channel.send(`${id} is rank ${rank} and not promotable.`)
} else {
msgObject.channel.send(`${id} is rank ${rank} and promotable.`)
roblox.promote(groupId, id)
.then(function (roles: { oldRole: { Name: any; }; newRole: { Name: any; }; }) {
msgObject.channel.send(`Promoted from ${roles.oldRole.Name} to ${roles.newRole.Name}`)
}).catch(console.error)
.then(msgObject.channel.send("Failed to promote."))
}
}).catch(console.error)
.then(
msgObject.channel.send("Couldn't get him in the group."));
}).catch(console.error)
.then(
msgObject.channel.send(`Sorry, but ${username} doesn't exist on ROBLOX.`));
} else {
msgObject.channel.send("Please enter a username.")
}
return;
}
}
答案 0 :(得分:0)
方法find('name', 'name')
已从discord.js
使用find(role => role.name === 'value')
删除
但是我建议您使用role.id
进行检查,因为它更安全,您可以执行以下检查:
if (!msgObject.member.roles.has('roleID')) return msgObject.channel.send(`Nice try ${msgObject.author.username} but you don't have permission to promote members!`)
您的问题的解决方案:
import * as Discord from "discord.js";
import { IBotCommand } from "../api";
import * as ConfigFile from "../config";
let express = require("express");
let roblox = require('noblox.js');
export default class Promote implements IBotCommand {
private readonly _command = "promote";
help(): string {
return "Promote members in the Roblox group."
}
isThisCommand(command: string): boolean {
return command === this._command;
}
async runCommand(args: string[], msgObject: Discord.Message, client: Discord.Client): Promise<void> {
if (!msgObject.member.roles.find(role => role.name === 'Council')) {
msgObject.channel.send(`Nice try ${msgObject.author.username} but you don't have permission to promote members!`)
.catch(console.error);
return;
}
let groupId = 5293276;
let maximumRank = ConfigFile.config.maximum_rank
let username = args[0]
if (username) {
msgObject.channel.send(`Checking ROBLOX for ${username}`)
roblox.getIdFromUsername(username)
.then(function (id: any) {
roblox.getRankInGroup(groupId, id)
.then(function (rank: number) {
if (maximumRank <= rank) {
msgObject.channel.send(`${id} is rank ${rank} and not promotable.`)
} else {
msgObject.channel.send(`${id} is rank ${rank} and promotable.`)
roblox.promote(groupId, id)
.then(function (roles: { oldRole: { Name: any; }; newRole: { Name: any; }; }) {
msgObject.channel.send(`Promoted from ${roles.oldRole.Name} to ${roles.newRole.Name}`)
}).catch(console.error)
.then(msgObject.channel.send("Failed to promote."))
}
}).catch(console.error)
.then(
msgObject.channel.send("Couldn't get him in the group."));
}).catch(console.error)
.then(
msgObject.channel.send(`Sorry, but ${username} doesn't exist on ROBLOX.`));
} else {
msgObject.channel.send("Please enter a username.")
}
return;
}
}