Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript discord.js message.author.id在dms中返回未定义,但在服务器中工作_Javascript_Discord.js - Fatal编程技术网

Javascript discord.js message.author.id在dms中返回未定义,但在服务器中工作

Javascript discord.js message.author.id在dms中返回未定义,但在服务器中工作,javascript,discord.js,Javascript,Discord.js,好吧,我用一个验证系统制作了这个机器人,但是 let memberTarget=client.guilds.cache.get('811543610897989683')。members.cache.get(message.author.id) 部件中有问题消息。author.id部件似乎在dms中与bot一起不起作用。它只在我在服务器上运行一次命令后才起作用,然后当我重新启动bot时,它在dms中不再起作用,有什么方法可以使它起作用吗 我的代码的其余部分: const fetch = requ

好吧,我用一个验证系统制作了这个机器人,但是
let memberTarget=client.guilds.cache.get('811543610897989683')。members.cache.get(message.author.id)
部件中有问题消息。author.id
部件似乎在dms中与bot一起不起作用。它只在我在服务器上运行一次命令后才起作用,然后当我重新启动bot时,它在dms中不再起作用,有什么方法可以使它起作用吗

我的代码的其余部分:

const fetch = require('node-fetch')
const ignSchema = require('../schemas/ign-schema')
const mongo = require('../mongo')
const Discord = require('discord.js')
const client = new Discord.Client


module.exports = {
    commands: ['verifyme'],
    minArgs: 0,
    maxArgs: null,
    expectedArgs: "<minecraft name>",
    callback: async (message, arguments, text,  client, e) => {
      
      
        const playerName = arguments.join(' ')
        

        

        fetch(`https://api.hypixel.net/player?key=MY_API_KEY&name=${playerName}`)
        .then(response => response.json())
        .then(async data => {
          


            player = data
            const target = message.author
            const author2 = message.author.tag
            const uuid = data["player"]["uuid"]
           const discordid = data["player"]["socialMedia"]["links"]["DISCORD"]
           
           
           const guildSetup = '712363102737530931'
          const guildSetup2 = '811543610897989683'
          
         

            let verifyRole = client.guilds.cache.get('811543610897989683').roles.cache.find(role => role.name === '[Verified]');
           
            let memberTarget = client.guilds.cache.get('811543610897989683').members.cache.get(message.author.id);

            const guildId = '811543610897989683'
            const userId = message.author.id
            const UUID = uuid
            const _id = UUID
            const author = message.author
         
            
           

           if(discordid == author2) {
            
            await mongo().then(async mongoose => {
              try {
                const results2 = await ignSchema.findOne({
                  _id,
                  
                })
                const { UUID, userData, discordName } = results2
                
               message.reply(`dd ${memberTarget}`)
                if (UUID == uuid) {
                  if (author2 == discordName) {
                    

                    if (memberTarget.roles.cache.some(role => role.name === "[Verified]")) {
                      message.reply('you are already verified')
                      memberTarget.roles.add(verifyRole)
                    } else {
                    memberTarget.roles.add(verifyRole)
                    message.reply('welcome back')
                    }
                  } else {


                    message.reply(`you already used this minecraft account to verify ${discordName}, if you want to change this please contact <@390929478790152192>`)
                    mongoose.connection.close()
                    return
                  }
                
        
                
                } else {

                }
              } catch {
                console.log(e)

                

                const userData = {
                  
                 
                  timestamp: new Date().getTime(),
                  
                }
                await mongo().then(async (mongoose) => {
                  try {
                    await ignSchema.findOneAndUpdate({
                      _id
                    },
                    {
                      
                      UUID,
                      discordName: author2,
                      HypixelName: playerName,
                      userId: userId,
                      guildId: guildId,


                      $push: {
                        userData: userData
                      },
                     
                      
                    }, {
                      upsert: true
                    })

                    memberTarget.roles.add(verifyRole)
                    message.reply('you are succesfully verified')

                  } finally {
                    mongoose.connection.close()
                    
               
                  }
                })
              }
            })
            } else {
            message.reply(`change your linked discord account in hypixel from ${discordid} to ${author2},`)
    
           }
           console.log(`${discordid}`)
           
           
           
        })
        
        
        .catch(error => {
          console.log("Network error", error)
          message.reply(`error: could not find a player named: ${playerName} check if you ever joined hypixel or try again later`)
          return
        })
        

    },
 
  }
const fetch=require('node-fetch')
常量ignSchema=require(“../schemas/ign schema”)
const mongo=require(“../mongo”)
const Discord=require('Discord.js')
const client=new Discord.client
module.exports={
命令:['verifyme'],
尖塔:0,
maxArgs:null,
预期的args:“”,
回调:异步(消息、参数、文本、客户端、e)=>{
const playerName=arguments.join(“”)
取回(`https://api.hypixel.net/player?key=MY_API_KEY&name=${playerName}`)
.then(response=>response.json())
。然后(异步数据=>{
播放器=数据
const target=message.author
const author2=message.author.tag
常量uuid=数据[“玩家”][“uuid”]
const discordid=data[“player”][“socialMedia”][“links”][“DISCORD”]
const guildSetup='712363102737530931'
const guildSetup2='811543610897989683'
让verifyRole=client.guilds.cache.get('811543610897989683').roles.cache.find(role=>role.name==='[Verified]');
让memberTarget=client.guilds.cache.get('811543610897989683').members.cache.get(message.author.id);
const Guidid='811543610897989683'
const userId=message.author.id
常量UUID=UUID
常数_id=UUID
const author=message.author
if(discordid==author2){
等待mongo()。然后(异步mongoose=>{
试一试{
const results2=await ignSchema.findOne({
_身份证,
})
const{UUID,userData,discorname}=results2
message.reply(`dd${memberTarget}`)
如果(UUID==UUID){
if(author2==不协调名称){
if(memberTarget.roles.cache.some(role=>role.name==“[Verified]”){
message.reply('您已被验证')
memberTarget.roles.add(verifyRole)
}否则{
memberTarget.roles.add(verifyRole)
message.reply('欢迎回来')
}
}否则{
message.reply(`您已使用此minecraft帐户验证${discorname},如果要更改此帐户,请联系`)
mongoose.connection.close()
返回
}
}否则{
}
}抓住{
控制台日志(e)
常量用户数据={
时间戳:新日期().getTime(),
}
等待mongo()。然后(异步(mongoose)=>{
试一试{
等待ignSchema.findOneAndUpdate({
_身份证
},
{
UUID,
不协调名称:author2,
HypixelName:playerName,
userId:userId,
吉尔迪德:吉尔迪德,
$push:{
userData:userData
},
}, {
厄普塞特:是的
})
memberTarget.roles.add(verifyRole)
message.reply('您已成功验证')
}最后{
mongoose.connection.close()
}
})
}
})
}否则{
reply(`将Hypix中链接的discord帐户从${discordid}更改为${author2},`)
}
console.log(`${discordid}`)
})
.catch(错误=>{
日志(“网络错误”,错误)
message.reply(`error:找不到名为:${playerName}的玩家请检查您是否加入过hypixel,或稍后再试`)
返回
})
},
}

如果您使用的是dm频道:

if(message.channel.type==“dm”){
//你可以在这里做任何你想做的事情。在我的例子中,我使用console.log()函数。
//因为您需要用户ID,所以可以在此处使用message.author.ID属性。
log(`Received DM from${message.author.tag},DM content为`,message.content);
}
当然,您不需要获取用户,因为dm中有1个用户。只需使用:

let user=message.author;

client.guilds.cache.get基本上是获取我给它的id的帮会,这样我可以在他们在dms中验证自己后在我的服务器上给他们一个角色,谢谢你的回复,我现在就试试我知道代码的作用了,但是,你认为特定于公会的代码在dm中如何工作?特定于公会的代码是什么意思?你认为
client.guilds.cache.get
如何工作?你不能在dm中使用此代码,因为dm不是公会。有人告诉我,我必须使用此代码,以便从dms中为某人指定特定公会中的角色