首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Send不是函数discord.js

Send不是函数discord.js
EN

Stack Overflow用户
提问于 2018-12-12 07:46:40
回答 3查看 5.5K关注 0票数 0

我试图向通道发送一条消息,但一直收到错误: send is not a function.I,我已经被这个问题困扰了一个多小时。

我尝试过的方法:使用sendMessage尝试阅读discord.js文档,但似乎根本不起作用。

下面是我的代码:

代码语言:javascript
复制
//Grab the Discord Library
const Discord = require("discord.js");

//What will connect to the server.
const bot = new Discord.Client();

//
bot.on('ready', () => {
  console.log("Connected as " + bot.user.tag)

  //Shows and set the activity of the user.
  bot.user.setActivity("El Professor build me", {type: "Watching"})
  //Inform you of the servers this bot is connected to.
  bot.guilds.forEach((guild) => {
    console.log(guild.name)
    guild.channels.forEach((channel) => {
      console.log(` - ${channel.name} ${channel.type} ${channel.id}`)
    })
    //Voice Channel ID = 
  })
  var generalChannel = bot.channels.get("123456789").send("Hello World")
})

错误消息:

代码语言:javascript
复制
C:\Users\F4_ALFA\documents\FirstDiscordBot\index.js:21
  var generalChannel = bot.channels.get("123456789").send("Hello World")
                                                              ^

TypeError: bot.channels.get(...).send is not a function
    at Client.bot.on (C:\Users\F4_ALFA\documents\FirstDiscordBot\index.js:21:63)
    at Client.emit (events.js:194:15)
    at WebSocketConnection.triggerReady (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\WebSocketConn
ection.js:125:17)
    at WebSocketConnection.checkIfReady (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\WebSocketConn
ection.js:141:61)
    at GuildCreateHandler.handle (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\packets\handlers\Gui
ldCreate.js:13:31)
    at WebSocketPacketManager.handle (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\packets\WebSocke
tPacketManager.js:103:65)
    at WebSocketConnection.onPacket (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\WebSocketConnecti
on.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\discord.js\src\client\websocket\WebSocketConnect
ion.js:296:17)
    at WebSocket.onMessage (C:\Users\F4_ALFA\documents\FirstDiscordBot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:189:13)
EN

回答 3

Stack Overflow用户

发布于 2018-12-18 12:35:50

channels属性返回一个包含IDChannel object对的Collection

Channel类可以表示任何不一致的通道。您无法通过它发送任何消息,因为它没有send()方法。

票数 0
EN

Stack Overflow用户

发布于 2019-07-22 04:52:29

我以前用过这个client.guilds.find(x => x.name === "ChatLogs").channels.find(y => y.name === "server-testing1").send(botEmbed)试试那个

票数 0
EN

Stack Overflow用户

发布于 2021-06-18 22:28:12

Discord.js使用缓存,而您的代码没有'.cache',您应该尝试一下

bot.channels.cache.get('id').send('Hello world!')

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53734071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档