繁体   English   中英

Discord.js:send() 不是 function

[英]Discord.js: send() is not a function

这是代码:

const Discord = require('discord.js')
const client = new Discord.Client()

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

    client.user.setActivity("the Universe", {type: 'WATCHING'})

    client.guilds.cache.forEach((guild)=>{
        console.log(guild.name)
        guild.channels.cache.forEach((channel)=>{
            console.log(` - ${channel.name} ${channel.type} ${channel.id} `)
        })
        // game-room-1 id: 774627995826520064
    })

    let gameRoom1 = client.channels.fetch('XXXX')
    gameRoom1.send("Hi @ARGØN");
})

client.login("TOKEN")

看到这个

gameRoom1.send()给出TypeError: gameRoom1.send is not a function 我该如何解决?

client.channels.fetch('XXXX') 返回一个 promise所以你需要先解决它:

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

    client.user.setActivity("the Universe", {type: 'WATCHING'})

    client.guilds.cache.forEach((guild)=>{
        console.log(guild.name)
        guild.channels.cache.forEach((channel)=>{
            console.log(` - ${channel.name} ${channel.type} ${channel.id} `)
        })
        // game-room-1 id: 774627995826520064
    })

    let gameRoom1 = await client.channels.fetch('XXXX')
    gameRoom1.send("Hi @ARGØN");
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM