javascript - 响应 discord.js 中的消息
问题描述
我想向某人发送以 s# 开头的消息的频道发送消息“E”。我有两个问题:
- 我有一个功能:
function read(msg)
{
if(msg[0] === "s" && msg[1] === "#") console.log("E");
}
而且我不知道如何使用某人作为“msg”发送的消息来调用此函数。
- 当我弄清楚如何做到这一点时,我想添加一个
channel.send("E");
,但我不知道如何获取消息发送到的频道的 ID。
解决方案
client.on('message', message => {
if(message.content.startsWith('s#')) console.log('s#');//check if the message starts with s#
});
message.channel.send('this is a reply to the message sent in this channel');
请参阅文档:https ://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-message
编辑(带有读取功能的整个代码):
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', message => {
read(message);
});
function read(message){
if(message.content.startsWith('s#')) console.log('s#');
}
client.login('your-token-here');
推荐阅读
- python - Python3 - 请求 - BS4 - Cloudflare -> 403 Forbidden not use Local Proxy
- javascript - 手动输入 URL 时,MERN 路由器链接不起作用
- python - python字典中的值被转换为双引号而不是单引号
- javascript - 使用 Jest 测试应该抛出错误的函数,但总是收到“函数未抛出”错误
- vb.net - 谷歌翻译 API 转换
- javascript - 产生战争时,Node_modules 复制需要太多时间
- perl - perl 脚本中的“无法获取终端大小”错误
- github - 我无法将我的网站部署到 Netlify
- python - 如何从用户输入正确添加到字典并使用 for 循环打印字典?
- octave - Octave 4.2.2 和 sympy 1.6