我已经编写了一个“say 命令”,它应该在我每次输入 -say 时执行一条消息。它工作正常,我只想将前缀设置为“?”而不是仅针对该命令的“-”,其他命令应该设置为主命令(“-”)。最重要的是,我希望它在输入命令后 _删除命令_,所以剩下的就是消息 [(e.g ?say hello --> (delete "?say hello" --> send message "hello" to text channel)].
我还想在我的命令中 指定 文本通道,而不是仅仅将其设置为发送仅向一个特定频道发送消息 [e.g -say (message) (text channel)]
如果它说“完成”之类的话,那也很酷。并在约 5 秒后删除该确认。
所以这是代码:
client.on('message', function(message) {
if(message.author.bot) return;
else if(isValidCommand(message, "say")) {
let sendMessage = message.content.substring(4);
let sendChannel = client.channels.cache.get('767374258492932106');
sendChannel.send(sendMessage)
}
});
在下文中,我将向您展示我的无效代码,试图将前缀设置为“?”但它没有执行,只说“声明或声明期待和遗漏或错误的标点符号..
client.on('message', function(message) {
if (['?'].every((prefix) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
else if(isValidCommand(message, "say")) {
let sendMessage = message.content.substring(4);
let sendChannel = client.channels.cache.get('767374258492932106');
sendChannel.send(sendMessage)
}
});
如果有人帮助我,我将不胜感激。谢谢!
原文由 Deazy 发布,翻译遵循 CC BY-SA 4.0 许可协议
我不确定你想用什么来实现
但这就是我要做的
使用 args、substring 和 switch 来识别命令。
的用法
编辑:表扬的用法就像
#generalTextChannel 标记频道的位置
或者
其中 767374258492932106 是频道 ID