0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[メモ]discord.jsとDiscordでPCログインアラートを作る。

Last updated at Posted at 2020-12-18

はじめに

これはPCがログインされる度に、Discordで警告を発せられるマシーンです。

ソースコード

startup.js

const Discord = require('discord.js');
const client = new Discord.Client();
const time = new Date();
var os = require("os");
var ip = require('ip');

client.on('ready', () => {
    const Channel = client.channels.cache.get("DISCORD_CHANNEL_ID");
    Channel.send(`<@DISCORD_USER_ID>\nTIME : ${time}\nHSOT NAME : ${os.hostname()}\nIP : ${ip.address()}\nDescription : PC is just started up.`);
    console.log(`\nTIME : ${time}\nHSOT NAME : ${os.hostname()}\nIP : ${ip.address()}\nDescription : PC is just started up.`);
});

client.login('DISCORD_BOT_ID');

/*
    ip.address() が使えない場合は、cmdでnpm i ipを入力してください。
    https://www.npmjs.com/package/ip
*/

run.bat

node X:\ファイルパス\startup.js

セットアップ

1.win + R
2.shell:startupを入力します。
3.run.batをスタートアップに置きます。
4.startup.jsをX:\ファイルパス\に置きます。

実行結果

cmd.exe
003.png

Discord
002.png

まとめ

このマシーンはいくつかのデメリットがあります:
1.cmd.exeが起動されたら、自動的に閉じることはできません。
2.PCがログインされる度に警告を発せられますが、PCが起動されてログインされていない場合は警告を発せられません。
3.cmd.exeが起動されてすぐ閉じられたら、警告を発せられません(プログラムはまだ実行されていませんから)。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?