【发布时间】:2022-01-15 20:46:09
【问题描述】:
我在specialCodes[letter] 中收到一个错误,说元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型和没有索引签名在类型上找到了“字符串”类型的参数
import { Message, MessageEmbed } from "discord.js";
import BaseCommand from "../../utils/structures/BaseCommand";
import DiscordClient from "../../client/client";
export default class EmojifyCommand extends BaseCommand {
constructor() {
super("emojify", "fun", []);
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
}
async run(client: DiscordClient, message: Message, args: Array<string>) {
const embedSpecify = new MessageEmbed();
embedSpecify
.setColor("RED")
.setDescription("Please specify a text to translate!");
if (!args.length) return message.reply({ embeds: [embedSpecify] });
const specialCodes = {
0: ":zero:",
1: ":one:",
2: ":two:",
3: ":three:",
4: ":four:",
5: ":five:",
6: ":six:",
7: ":seven:",
8: ":eight:",
9: ":nine:",
"#": ":hash:",
"*": ":asterisk:",
"?": ":grey_question:",
"!": ":grey_exclamation:",
" ": " ",
};
const text = args
.join(" ")
.toLowerCase()
.split("")
.map((letter) => {
if (/[a-z]/g.test(letter)) {
return `:regional_indicator_${letter}:`;
} else if (specialCodes[letter]) {
return `${specialCodes[letter]}`;
}
return letter;
})
.join("");
message.reply(text);
}
}
【问题讨论】:
标签: node.js typescript discord discord.js