如何获得自己的Discord机器人的启动时间?

时间:2020-07-13 06:45:50

标签: javascript discord.js

有人知道如何获得自己的Discord机器人的启动时间吗? (我不是指正常运行时间)(我正在寻找启动时间)

类似的东西:

在变量中。

开始时间 2020-12-31 12:12:12

3 个答案:

答案 0 :(得分:0)

您可以使用此事件来检测他何时在线:

link1

答案 1 :(得分:0)

我想做这样的事情: enter image description here

但是我得到了这样的东西,他甚至没有工作 enter image description here

而我未定义客户端的源代码就是这样:

const { Command, Client, CommandoClient} = require('discord.js-commando');
const date = require ('../../index.js')
const bot = new Client();
const { MessageEmbed } = require('discord.js');
const moment = require("moment"); 
require("moment-duration-format");


module.exports = class UptimeCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'uptime',
      aliases: ['alive', 'up'],
      memberName: 'uptime',
      group: 'other',
      description: "Replies with the bot's total uptime."
    });
  }
  run(message) {
    let totalSeconds = (client.uptime / 1000);
    let days = Math.floor(totalSeconds / 86400);
    let hours = Math.floor(totalSeconds / 3600);
    totalSeconds %= 3600;
    let minutes = Math.floor(totalSeconds / 60);
    let seconds = Math.floor(totalSeconds % 60);
    
    const duration =  moment.duration(client.uptime).format(" D [days], H [hrs], m [mins], s [secs]");

    console.log(seconds);
    const embed = new MessageEmbed()
     .setTitle('')
     .setAuthor("Lucky-Bot", message.author.displayAvatarURL())
     .setColor(0x2ECECE)
     .setDescription('')
     .addFields(
      { name: 'Lokaler Zeitraum', value:duration },
      { name: 'Laufzeit', value: '${days} Tage, ${hours} Stunden, ${minutes} Minuten und ${seconds} Sekunden', inline: true },
      { name: 'Gestartet', value: date, inline: true },
    )
     message.channel.send({embed});
  }
};

    

答案 2 :(得分:0)

const { CommandoClient, Client } = require('discord.js-commando');
const { Structures } = require('discord.js');
const discord = require('discord.js');
const path = require('path');
const { prefix, token, discord_owner_id } = require('./config.json');
const bot = new Client();

Structures.extend('Guild', function(Guild) {
  class MusicGuild extends Guild {
    constructor(client, data) {
      super(client, data);
      this.musicData = {
        queue: [],
        isPlaying: false,
        nowPlaying: null,
        songDispatcher: null,
        volume: 1
      };
      this.triviaData = {
        isTriviaRunning: false,
        wasTriviaEndCalled: false,
        triviaQueue: [],
        triviaScore: new Map()
      };
    }
  }
  return MusicGuild;
});

const client = new CommandoClient({
  commandPrefix: prefix,
  owner: discord_owner_id // value comes from config.json
});

client.registry
  .registerDefaultTypes()
  .registerGroups([
    ['music', 'Music Command Group'],
    ['gifs', 'Gif Command Group'],
    ['other', 'random types of commands group'],
    ['guild', 'guild related commands']
  ])
  .registerDefaultGroups()
  .registerDefaultCommands({
    eval: false,
    prefix: false,
    commandState: false
  })
  
  .registerCommandsIn(path.join(__dirname, 'commands'));


  
let _date;

  client.on("ready", () =>{
    _date = new Date();
    console.log(_date)
    console.log('Startet Up :) !')
    client.user.setStatus('dnd')
    client.user.setActivity('Simogus Livestream', {type: 'WATCHING'}, {url: 'www.twitch.tv/simogu'}).catch(console.error);
});



client.on('voiceStateUpdate', async (___, newState) => {
  if (
    newState.member.user.bot &&
    !newState.channelID &&
    newState.guild.musicData.songDispatcher &&
    newState.member.user.id == client.user.id
  ) {
    newState.guild.musicData.queue.length = 0;
    newState.guild.musicData.songDispatcher.end();
    return;
  }
  if (
    newState.member.user.bot &&
    newState.channelID &&
    newState.member.user.id == client.user.id &&
    !newState.selfDeaf
  ) {
    newState.setSelfDeaf(true);
  }
});

client.on('guildMemberAdd', member => {
  const channel = member.guild.channels.cache.find(ch => ch.name === 'Allgemein'); // change this to the channel name you want to send the greeting to
  if (!channel) return;
  channel.send(`Willkommen ${member} auf den Server von den Kings ? !`);
});

client.login(token);