gpt4 book ai didi

javascript - 如何让我的机器人向另一个 channel 发送消息?

转载 作者:行者123 更新时间:2023-11-30 20:05:26 25 4
gpt4 key购买 nike

所以我有一个机器人,当我执行命令/say 时,它会接受我说的任何话并删除我的消息。由于它在技术上仍会发送我的消息,因此人们会通过通知看到它,并且可以判断是我让机器人发送了文本。我和我的 friend 一起做这件事是为了好玩和恶作剧,所以我想找到一种方法让机器人从隐藏的文本 channel 获取我的/say 命令并将其放入通用 channel 。

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);

}
}
});

到目前为止,这是我的代码,我已经让它按照我想要的方式工作。我只需要有关如何将隐藏 channel 的消息复制到常规 channel 的帮助

最佳答案

假设您有一些名为 general 的 channel 。

下面会向它发送一条消息:

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)
}
})

关于javascript - 如何让我的机器人向另一个 channel 发送消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52979746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com