简体   繁体   English

类型错误:无法读取未定义的属性“发送”?

[英]TypeError: Cannot read property 'send' of undefined?

I'm trying to get my discord javascript discord bot to send me a dm using id but it keeps saying:我正在尝试让我的 discord javascript discord 机器人使用 id 向我发送 dm,但它一直在说:

TypeError: Cannot read property 'send' of undefined.类型错误:无法读取未定义的属性“发送”。

Any idea?任何的想法?

const Discord = require('discord.js');
const{prefix,token} = require('./config.json');
const bot = new Discord.Client();

bot.once('ready', () => {
  console.log(`Ready!`);
});

bot.on('message', message => {
  let e = message.content.split(" ");

  if(message.content.startsWith(`${prefix}help`))
  {
    if (message.channel.type == "dm")
    {
      message.author.send("use !send");

    }

  } 

  if(message.content.startsWith(`${prefix}send`))
  {
    if (message.channel.type == "dm")
    {
      try{
      message.author.send("Message sent");
      message.client.users.get("266928832726xxxxxxx").send("someMessage");
    }catch(e){console.log("[ERROR]",e)}
    }

  } 

})

bot.login(token); 

Okay so what you have to do in order to know what is the problem with send is, is to at first console.log(message) and check if you get the value called author and then check if author has value or method called send .好的,为了知道send的问题是什么,您必须做的是,首先是console.log(message)并检查您是否获得了名为author的值,然后检查author是否具有名为send的值或方法。

You const your client as bot const bot = new Discord.Client();你将你的客户端设置为 bot const bot = new Discord.Client();

And try get members as message.client.users.get("266928832726xxxxxxx") Message dont have property client.users so use bot.users.get()并尝试将成员获取为message.client.users.get("266928832726xxxxxxx")消息没有属性client.users所以使用bot.users.get()

bot.on('message', message => {
  let e = message.content.split(" ");

  if(message.content.startsWith(`${prefix}help`)){
    if (message.channel.type == "dm"){
      message.author.send("use !send");
    }
  }

  if(message.content.startsWith(`${prefix}send`)){
    if (message.channel.type == "dm"){
      message.author.send("Message sent");
      bot.users.get("266928832726xxxxxxx").send("someMessage").catch(console.error);
    }
  } 
})

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

相关问题 TypeError:无法读取未定义的属性“发送” - TypeError: Cannot read property 'send' of undefined UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“发送” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined TypeError:无法读取DM中未定义的属性“发送” - TypeError: Cannot read property 'send' of undefined with DM TypeError:无法读取未定义 discord 机器人的属性“发送” - TypeError: Cannot read property 'send' of undefined discord bot 类型错误:无法在 discord.js 读取未定义错误的属性“发送” - TypeError: Cannot read property 'send' of undefined erorr at discord.js AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性'__id' - AngularJS + Fullcalendar send error TypeError: Cannot read property '__id' of undefined 写入 discord bot 时出现“类型错误:无法读取未定义的属性‘发送’” - "TypeError: Cannot read property 'send' of undefined" while writing discord bot 类型错误:无法读取未定义的属性“发送”| Discord.JS - TypeError: Cannot read property 'send'of undefined | Discord.JS 如何解决 TypeError: Cannot read property 'send' of undefined in app.on - How to solve TypeError: Cannot read property 'send' of undefined in app.on TypeError:无法读取未定义的属性“0” - TypeError: Cannot read property '0' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM