【问题标题】:Discord.JS Message in a specific Channel特定频道中的 Discord.JS 消息
【发布时间】:2022-01-12 20:03:37
【问题描述】:

所以我是整个 Discord.JS 的新手,我正试图弄清楚如何让机器人在有新人加入时向 General Chat 写一条消息。

我见过很多人这样做:

const channel = client.channels.cache.find(channel => channel.name === channelName)
channel.send(message)

但这对我不起作用。每当我尝试使用channel.send(message) 发送消息时,它都会给我一条错误消息。

我也试过你用client.channels.cache.get(<Channel-ID>)做的版本

但这对我也不起作用。

【问题讨论】:

  • 分享你收到的错误信息。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: javascript typescript discord.js


【解决方案1】:

使用此代码类似于帖子:how to send a message to specific channel Discord.js

<client>.channels.fetch('<id>').then(channel => channel.send('<content>'))

示例

client.channels.fetch('922880975074127872')
.then(channel => channel.send(`Welcome, ${user}`))

【讨论】:

    猜你喜欢
    • 2021-08-21
    • 2020-04-04
    • 2020-05-22
    • 2021-10-19
    • 2021-08-09
    • 2021-02-11
    • 2020-06-25
    • 2022-01-25
    相关资源
    最近更新 更多