![](/img/trans.png)
[英]How can I make my discord bot only send a message if a user starts typing in a specific channel?
[英]How can I get my bot to send a message to another channel?
所以我有一個機器人,當我執行命令 /say 並刪除我的消息時,它會接受我所說的任何內容。 由於它仍然在技術上發送我的消息,人們會通過通知看到它,並且可以告訴我是我讓機器人發送文本的。 我這樣做是為了和我的朋友們一起做一件有趣的事情,所以我想找出一種方法讓機器人從隱藏的文本頻道獲取我的 /say 命令並將其放入通用頻道。
const Discord = require('discord.js') //Discord package
const client = new Discord.Client(); //New Discord Client
const prefix = '/'; //command prefix
client.on('ready', () => {
console.log('Bot is Online.');
});
client.on('message', message => {
if(message.member.roles.find('name', 'Bot')){ //only role 'Bot' can use the command
if (message.author.bot) return undefined; //bot does not reply to itself
let msg = message.content.toLowerCase();
let args = message.content.slice(prefix.length).trim().split(' '); //arguments
let command = args.shift().toLowerCase(); //shifts args to lower case letters
if (command === 'say'){
let say = args.join(' '); //space
message.delete(); //deletes the message you sent
message.channel.send(say);
}
}
});
到目前為止,這是我的代碼,我已經讓它按照我想要的方式工作。 我只需要有關如何將隱藏頻道的消息復制到通用頻道的幫助
假設您有一些名為general
頻道。
以下將向其發送消息:
client.on('message', message => {
if (message.author.bot) return undefined //bot does not reply to itself
let msg = message.content.toLowerCase()
let args = message.content
.slice(prefix.length)
.trim()
.split(' ') //arguments
let command = args.shift().toLowerCase() //shifts args to lower case letters
if (command === 'say') {
let say = args.join(' ') //space
message.delete() //deletes the message you sent
const generalChannel = message.guild.channels.find(channel => channel.name === "general")
generalChannel.send(say)
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.