[英]Discord.js Sending a message to another channel
我目前有一個工作腳本,它根據海報輸入的參數分配角色。 我想要做的是讓機器人向本地頻道發送一條消息,以便發布者知道它有效,然后向另一個頻道發送另一條消息,歡迎將角色授予服務器的用戶。 這就是我所擁有的:
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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.