Answer the question
In order to leave comments, you need to log in
How to translate code from python to node js?
I have a python code and I would like to translate it to node js, but my knowledge of python is very weak, the code itself is:
import time
@bot.event
async def on_ready():
print('Bot Connected')
global tdict
tdict = {}
await bot.change_presence(activity = discord.Game('r!help'))
@bot.event
async def on_voice_state_update(member, before, after):
author = member.id
if before.channel is None and after.channel is not None:
print('1')
t1 = time.time()
tdict[author] = t1
elif before.channel is not None and after.channel is None and author in tdict:
t2 = time.time()
print('0')
print(t2-tdict[author])
Answer the question
In order to leave comments, you need to log in
Below is your python
code in JS using the discord-js library
const Discord = require("discord.js");
const bot = new Discord.Client();
bot.on("ready", async () => {
console.log("Bot Connected");
global.tdict = {};
await bot.user.setActivity("r!help", { type: "PLAYING" });
});
bot.on("voiceStateUpdate", async (before, after) => {
const author = before.member.id || after.member.id;
if (!before.channel && after.channel) {
console.log("1");
const t1 = Math.floor(Date.now() / 1000);
global.tdict[author] = t1;
} else if (before.channel && !after.channel && global.tdict.hasOwnProperty(author)) {
const t2 = Math.floor(Date.now() / 1000);
console.log("0");
console.log(t2 - global.tdict[author]);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question