第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord bot 在特定頻道發(fā)送消息

Discord bot 在特定頻道發(fā)送消息

繁星coding 2023-03-18 16:51:48
我知道之前有人問過這個問題,但我找不到適合我的解決方案。但我希望我的 discord 機器人(當我編寫命令時)在特定頻道上發(fā)送消息,并且僅在該頻道上發(fā)送消息。目前,我的工作區(qū)中只有基本文件和文件夾 + 一個命令文件夾。索引文件如下所示: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'); },};
查看完整描述

1 回答

?
精慕HU

TA貢獻1845條經(jīng)驗 獲得超8個贊

client不是你從需要discord.js模塊中得到的東西。它是在您的機器人開始時創(chuàng)建的,您可以通過以下方式獲取您的客戶端實例message.client

const?channel?=?message.client.channels.cache.get('CHANNEL_ID').send('message');


查看完整回答
反對 回復 2023-03-18
  • 1 回答
  • 0 關注
  • 392 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號