机器人在特定频道发送消息
Bot sending a message in certain channel
我想要一个类似于 "say" 命令的命令,但它仅限于 bot 所有者,并且只能在特定服务器的一个通道中发送。有什么建议吗?
这是我的代码(不工作 atm):
client.on("message", (message) => {
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if(command === "+ubersay") {
if(message.author.id !== process.env.ownerID) return;
const sayMessage = args.join(" ");
message.delete().catch(O_o=>{});
client.channels.get(process.env.specifiedChannel).send(sayMessage);
}
});
代码应该可以完美运行,唯一可能有问题的是您的 const args = message.content.slice(prefix.length).trim().split(/ +/g);
与 if(command === "+ubersay") {
结合使用,因为这要求您的命令以 [prefix]+ubersay
格式使用所以如果你的前缀是 + 你需要做 ++ubersay
我想要一个类似于 "say" 命令的命令,但它仅限于 bot 所有者,并且只能在特定服务器的一个通道中发送。有什么建议吗?
这是我的代码(不工作 atm):
client.on("message", (message) => {
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if(command === "+ubersay") {
if(message.author.id !== process.env.ownerID) return;
const sayMessage = args.join(" ");
message.delete().catch(O_o=>{});
client.channels.get(process.env.specifiedChannel).send(sayMessage);
}
});
代码应该可以完美运行,唯一可能有问题的是您的 const args = message.content.slice(prefix.length).trim().split(/ +/g);
与 if(command === "+ubersay") {
结合使用,因为这要求您的命令以 [prefix]+ubersay
格式使用所以如果你的前缀是 + 你需要做 ++ubersay