【问题标题】:Send is not defined (suggest command)发送未定义(建议命令)
【发布时间】:2020-08-10 07:19:20
【问题描述】:

TypeError: Cannot read property 'send' of undefined我做错了什么?我看不出我应该在哪里定义它。可能只是我忘记了一件愚蠢的事情。我将不胜感激所有改进/建议。

module.exports = {
    name: 'suggest',
    aliases: ['sug', 'suggestion'],
    description: 'Suggest something for the Bot',
    execute( client, message, args) {
        const filter = m => m.author.id === message.author.id;
        message.channel.send(Suggest something for the Bot or send "cancel" to cancel the suggestion)
        message.channel.awaitMessages(filter, {max: 1,})
            .then(async(collected) => {
                if (collected.first().content.toLowerCase() == 'cancel') {
                message.reply("The suggestion has been cancelled.")
                } 
                else { client.channels.get("702825446248808519").send(collected.first().content)
                    message.channel.send(Your suggestion has been sent)
                }
            })
    },
    catch (err) {
        console.log(err)
    }
};

【问题讨论】:

  • 显然,message.channel 是未定义的。消息设置在哪里?
  • 消息在execute()中
  • message 是 execute() 的第二个参数,但显然是调用者设置的。调用者将其设置为什么?

标签: javascript bots discord.js send defined


【解决方案1】:
message.channel.send(Suggest something for the Bot or send "cancel" to cancel the suggestion) 

这行不通,使用此代码您试图发送一个不存在的 var,我猜您正在尝试发送一个文本,所以它应该如下所示:

message.channel.send('Suggest something for the Bot or send "cancel" to cancel the suggestion')

这里也一样:

message.channel.send(Your suggestion has been sent)

变成:

message.channel.send('Your suggestion has been sent')

另外,如果您使用的是 discord.js v12,请将 client.channels.get 更改为 client.channels.cache.get

希望对你有帮助

【讨论】:

  • 啊,我想我自己修复了它,我的意思是 2 个月前,但仍然感谢,我会将其标记为正确。
  • 没问题我只是路过看到它,如果有些人有同样的问题,至少他们有一些关于错误是什么的线索
猜你喜欢
  • 2019-05-14
  • 1970-01-01
  • 1970-01-01
  • 2020-12-15
  • 2021-12-20
  • 2021-07-19
  • 2019-10-12
  • 1970-01-01
  • 2021-04-08
相关资源
最近更新 更多