我知道之前已经有人问过这个问题,但是我找不到适合我的解决方案。但是我希望我的不和谐机器人(当我编写命令时)在特定的通道上并且仅在该通道上发送消息。
当前,我的工作区中只有基本文件和文件夹,还有一个commands文件夹。 索引文件如下所示:
const discord = require('discord.js');
const config = require('./config.json');
const client = new discord.Client();
const prefix = '>';
const fs = require('fs');
client.commands = new discord.Collection();
const commandFiles = fs
.readdirSync('./commands/')
.filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log(`${client.user.username} is online`);
});
client.on('message', (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ + /);
const command = args.shift().toLowerCase();
if (command === 'cmd') {
client.commands.get('cmd').execute(message, args);
}
});
client.login('CLIENT_ID');
然后在与index.js相同级别的目录中有一个名为“ commands”的文件夹,其中包含如下所示的cmd.js
const client = require('discord.js');
module.exports = {
name: 'cmd',
description: 'cmd',
execute(message, args) {
const channel = client.channels.cache.get('CHANNEL_ID').send('message');
},
};
答案 0 :(得分:1)
<div clas="main-container" *ngFor="let subsection of section.subSections>
<a mat-list-item"
(click)="navigateToSubsection(section.id,subsection.id)">{{subsection.sectionName}}
</a>
<hr/>
</div>
不是需要client
模块而获得的。它是在您的漫游器开始时创建的,您可以通过message.client
discord.js