繁体   English   中英

有人可以帮助我解决错误吗?

[英]Can someone help me with an err?

所以我为我的不和谐机器人做了一个秒表命令,但它说:类型错误:无法读取message.guild.id上未定义的属性“id”)请帮助我试图找出为什么会发生这种情况一周

const Discord = require('discord.js');
const StopWatch = require("timer-stopwatch-dev"); 
const moment = require('moment');

module.exports = {
    name: 'duty',
    description: "This is a stopwatch command",
    async execute(client, message, args, CurrentTimers) {
      try {
          let guildTimers = CurrentTimers.get(message.guild.id);
          let guildTimersUser = guildTimers.get(message.author.id);
          if(!guildTimersUser){ guildTimers.set(message.author.id, new StopWatch()); guildTimersUser = guildTimers.get(message.author.id); };

 if(!args[0] || args[0] === 'on'){
   if(guildTimersUser.isRunning()) return message.channel.send('You need to stop your shift first!')
   guildTimersUser.start();
   message.channel.send('You have started your shift')
 } else if(args[0] === 'off'){
  if(!guildTimersUser.isRunning()) return message.channel.send('You need to start the Stopwatch first!')
  guildTimersUser.stop();
  message.channel.send(new Discord.RichEmbed().setTitle('You have stopped the Stopwatch!').setDescription('Total Time: ' + dhm(guildTimersUser.ms)).setTimestamp());
 }

 }
 
 catch(err) {
   console.log(err)
 }

 function dhm(ms){
  days = Math.floor(ms / (24*60*60*1000));
  daysms=ms % (24*60*60*1000);
  hours = Math.floor((daysms)/(60*60*1000));
  hoursms=ms % (60*60*1000);
  minutes = Math.floor((hoursms)/(60*1000));
  minutesms=ms % (60*1000);
  sec = Math.floor((minutesms)/(1000));
  return days+" days, "+hours+" hours, "+minutes+" minutes, "+sec+" seconds.";
    }
   }
  }

可以创建Discord 嵌入并将其发送到频道。

从文档:

// at the top of your file
const Discord = require('discord.js');

// inside a command, event listener, etc.
const exampleEmbed = new Discord.MessageEmbed()
    .setColor('#0099ff')
    .setTitle('Some title')
    .setURL('https://discord.js.org/')
    .setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
    .setDescription('Some description here')
    .setThumbnail('https://i.imgur.com/wSTFkRM.png')
    .addFields(
        { name: 'Regular field title', value: 'Some value here' },
        { name: '\u200B', value: '\u200B' },
        { name: 'Inline field title', value: 'Some value here', inline: true },
        { name: 'Inline field title', value: 'Some value here', inline: true },
    )
    .addField('Inline field title', 'Some value here', true)
    .setImage('https://i.imgur.com/wSTFkRM.png')
    .setTimestamp()
    .setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');

channel.send(exampleEmbed);

暂无
暂无

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

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