javascript - Discord.js 向另一个频道发送消息
问题描述
我目前有一个工作脚本,它根据海报输入的参数分配角色。我想要做的是让机器人向本地频道发送一条消息,以便发布者知道它有效,然后向另一个频道发送另一条消息,欢迎将角色获得服务器的用户。这就是我所拥有的:
const { client } = require('../main.js');
module.exports = {
name: 'roles',
description: "This is the command to give new recruits their role!",
args: true,
usage: '<department> <@user>',
execute(message, args){
//variables are defined here
const channel = client.channels.cache.get('the channel id');
message.delete(); //This deletes the posters command message
if (!message.mentions.users.size){
return message.channel.send('Please make sure to tag someone!');
else if(args[0] === 'bcso'){
user.roles.add(bcso);
user.roles.add(member);
user.roles.add(whitelist)
user.roles.remove(leoR);
message.channel.send(`${user} is now a full member of the BCSO`);
channel.send('Message goes here');
}
//rest of my code
但我在控制台中遇到的错误是:“TypeError:无法读取未定义的属性‘通道’”
只是为了确认我设置了一个高级代码处理程序,因此此代码位于其自己文件中的命令文件夹内。
想法?
解决方案
看来您的导入client
未定义。可能是因为您没有在main.js
文件中正确导出它。
幸运的是,您可以简单地使用该消息来查找频道。为此,您需要更改client.channels.cache.get('the channel id');
为message.client.channels.cache.get('ID HERE');
推荐阅读
- angular - Cordova 中的 Razorpay 集成 [RazorPayCheckout 未定义]
- python - GET 404 未能在烧瓶引导程序中加载资源错误
- php - PHP Wamp 服务器 - 一台服务器上有 2 个 SSL 证书
- validation - Golang 验证器:structExcept
- javascript - React / PrimeReact 应用程序未使用 JSON 从 Web 服务呈现数据表内容
- swift - UIView 未使用模型初始化
- php - 在 Symfony 中反序列化对象的索引数组
- sql - 选择一行Oracle中的所有值(所有行)
- java - 更新了错误“JDK7u25 Codebase manifest 属性应该用于限制 JAR 再利用。请设置 manifest.custom.codebase”的解决方案
- r - 应用 fGarch 包拟合简单 GARCH 模型时的警告消息