您好,我正在嘗試為我的 Discord 機器人創建一個 nick 命令,但我收到了這個錯誤。我的機器人正在使用型別腳本。
錯誤:運算式 expected.ts (1109)
當我更換
const 提到的成員 = 訊息?message.mentions.members?.first():
和
const 提到的成員 = 訊息?message.mentions.members?.first(),
它修復了 const nickName = args.slice(1).join(" "); 但給了我錯誤
':' 預期 ts(1005) [19,76]
代碼:
import "discord.js";
import { ICommand } from "wokcommands";
export default{
name: 'nickname',
category: 'Moderation',
aliases: ['nick'],
description: 'Nicks a user',
permissions: ['MANAGE_NICKNAMES'],
slash: 'both',
testonly: true,
callback: async({ client, message, args}) => {
const mentionedMember = message? message.mentions.members?.first() :
const nickName = args.slice(1).join(" ");
//gets the nickname
if (!args[0]) return message.reply('You did not mention a user for me to change there nickname!');
if (!mentionedMember) return message.reply('Please mention a user for me to change there nickname \`>nickname @user nickname\`');
if (!nickName) return message.reply('Please mention a nickname for me to change this users nickname');
//returns an error message if there isn't a user mentioned or the new nick is not specified
if (!mentionedMember.kickable) return message.reply('This User Has a senior rank then me i cant change his nickname')
//checks if the user that has been mentioned is below the bot in rank of roles, if not the bot won't be able to change the nickname
await mentionedMember.setNickname(nickName) && await message.reply(`Successfuly Changed ${mentionedMember} Nickname to ${nickName}`);
//changes the nickname to the specified nickname and sends a message Successfuly
},
}as ICommand
uj5u.com熱心網友回復:
看起來您正在嘗試執行三元陳述句,它是 if-else 陳述句的簡寫版本,用 ? 和:,在哪里?是條件為真時應該發生的情況,而 : 是條件為假時應該發生的情況。例如:
message = (hasApplesauce) ? 'we have applesauce!' : 'no applesauce :(';
此代碼段將訊息設定為“我們有蘋果醬!” 如果 hasApplesauce 為真,并在 hasApplesauce 布林值為假時將其設定為“no applesauce :(”。上面的陳述句等價于普通的 if-else 條件代碼:
if (hasApplesauce)
{
message = 'we have applesauce!';
}
else
{
message = 'no applesauce :(';
}
您可以用類似于任何其他 if 陳述句的其他條件陳述句替換該布林值。編譯器可能正在閱讀您的訊息?在導致錯誤的行上作為三元陳述句的開頭,這就是為什么它希望您在它之后添加一個等效的 :。如果您只是想做一個 ? 變數檢查,你想改變行
const mentionedMember = message? message.mentions.members?.first() :
進入
const mentionedMember = message?.mentions.members?.first();
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/368254.html
