Code Not working

const Discord = require('discord.js');

const client = new Discord.Client({
intents: {
typing: false,
presences: false
}
});

client.on('ready', async () => {
console.log('Logged in as ' + client.user.name);
updatePresence();
});

const updatePresence = () => {
setInterval(() => {
const currentTime = new Date().toLocaleString('en-US', {
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: true
});

client.user.setPresence({
activity: {
type: 'watching',
name: currentTime
}
});
}, 60000);
};

client.login('');
const Discord = require('discord.js');

const client = new Discord.Client({
intents: {
typing: false,
presences: false
}
});

client.on('ready', async () => {
console.log('Logged in as ' + client.user.name);
updatePresence();
});

const updatePresence = () => {
setInterval(() => {
const currentTime = new Date().toLocaleString('en-US', {
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: true
});

client.user.setPresence({
activity: {
type: 'watching',
name: currentTime
}
});
}, 60000);
};

client.login('');
28 Replies
d.js toolkit
d.js toolkit•2y ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
ThourCS
ThourCSOP•2y ago
[email protected] Node v18.17.1 I just want to show GMT -7 Timezone in my presence
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
can you please help me out, much appreciated. I am new to discord.js
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs•2y ago
guide Popular Topics: Gateway Intents read moreguide Popular Topics: Bot Configuration and Utility - How do I set my status to "Watching/Listening to/Competing in ..."? If you would like to set your activity upon startup, you can use the ClientOptions object to set the appropriate Presence data. read more
ThourCS
ThourCSOP•2y ago
can u please fix it for me?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
client.user.setPresence({ activities: [{ name: 'activity' }], status: 'idle' });
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
workin on it I am actually from Python discord.py to discord.js so idk javascript much my python code:
import discord
import datetime
from discord.ext import commands, tasks

intents = discord.Intents.default()
intents.typing = False
intents.presences = False

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
update_presence.start()

@tasks.loop(minutes=1)
async def update_presence():
current_time = datetime.datetime.utcnow() - datetime.timedelta(hours=7)
timestamp = current_time.strftime('%A, %I:%M %p')
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f'{timestamp}'))

@update_presence.before_loop
async def before_update_presence():
await bot.wait_until_ready()
import discord
import datetime
from discord.ext import commands, tasks

intents = discord.Intents.default()
intents.typing = False
intents.presences = False

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
update_presence.start()

@tasks.loop(minutes=1)
async def update_presence():
current_time = datetime.datetime.utcnow() - datetime.timedelta(hours=7)
timestamp = current_time.strftime('%A, %I:%M %p')
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f'{timestamp}'))

@update_presence.before_loop
async def before_update_presence():
await bot.wait_until_ready()
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
This discord is for my community server i would love if u can fix it, need to make it online asap 😦
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
I was using python, now new VPS not working with python oh ok. np
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
I understood that I need to do use this:
client.user.setActivity('activity', { type: ActivityType.Watching });
client.user.setActivity('activity', { type: ActivityType.Watching });
but where do I insert my currentTime in it? and can u help me fix just my imports?
const Discord = require('discord.js');

const client = new Discord.Client({
intents: {
typing: false,
presences: false
}
});
const Discord = require('discord.js');

const client = new Discord.Client({
intents: {
typing: false,
presences: false
}
});
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
is this correct?
d.js docs
d.js docs•2y ago
guide Popular Topics: Gateway Intents read more
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
ok one sec
const updatePresence = () => {
setInterval(() => {
const currentTime = new Date().toLocaleString('en-US', {
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: true
});

client.user.setPresence({ activities: [{ name: currentTime }], status: 'online' });
}, 60000);
};
const updatePresence = () => {
setInterval(() => {
const currentTime = new Date().toLocaleString('en-US', {
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: true
});

client.user.setPresence({ activities: [{ name: currentTime }], status: 'online' });
}, 60000);
};
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
much better now?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ThourCS
ThourCSOP•2y ago
Error: RangeError [BitFieldInvalid]: Invalid bitfield flag or number: [object Object].
const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});

client.on('ready', async () => {
console.log('Logged in as ' + client.user.name);
updatePresence();
});

const updatePresence = () => {
setInterval(() => {
const currentTime = new Date().toLocaleString('en-US', {
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: true
});

client.user.setPresence({ activities: [{ name: currentTime }], status: 'online' });
}, 60000);
};
const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});

client.on('ready', async () => {
console.log('Logged in as ' + client.user.name);
updatePresence();
});

const updatePresence = () => {
setInterval(() => {
const currentTime = new Date().toLocaleString('en-US', {
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: true
});

client.user.setPresence({ activities: [{ name: currentTime }], status: 'online' });
}, 60000);
};
I am close it goes online but no data is to be shown
ThourCS
ThourCSOP•2y ago
ThourCS
ThourCSOP•2y ago
ok it shows but its showing my time lol i want -7 GMT
const currentTime = new Date().toLocaleString('en-US', {
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: true,
timeZone: 'America/Los_Angeles'
});
const currentTime = new Date().toLocaleString('en-US', {
weekday: 'long',
hour: 'numeric',
minute: 'numeric',
hour12: true,
timeZone: 'America/Los_Angeles'
});
I tried this, still same.

Did you find this page helpful?