vo0ov
vo0ov
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by vo0ov on 11/7/2023 in #djs-questions
How get arguments in slash command?
No description
13 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by vo0ov on 11/7/2023 in #djs-questions
How add arguments to slash command?
No description
6 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by vo0ov on 11/7/2023 in #djs-questions
How get bot latency?
bot.ws.ping return -1 bot.ping return NaN Date.now() - message.createdTimestamp not is latency
10 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by vo0ov on 11/7/2023 in #djs-questions
How to mention slash command?
No description
5 replies
DIAdiscord.js - Imagine a boo! πŸ‘»
Created by vo0ov on 11/6/2023 in #djs-questions
Why is my Discord bot not working on Node.js?
The bot starts, but does not respond to !ping and !sum.
const { Client, GatewayIntentBits } = require('discord.js');

const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages,]
});
const prefix = "!";

bot.on('ready', async () => {
console.log(`${bot.user.username} запустился`)
});

bot.on("messageCreate", function(message) {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;

const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();

if (command === "ping") {
const timeTaken = Date.now() - message.createdTimestamp;
message.reply(`Pong! This message had a latency of ${timeTaken}ms.`);
}

else if (command === "sum") {
const numArgs = args.map(x => parseFloat(x));
const sum = numArgs.reduce((counter, x) => counter += x);
message.reply(`The sum of all the arguments you provided is ${sum}!`);
}
});

bot.login('');
const { Client, GatewayIntentBits } = require('discord.js');

const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages,]
});
const prefix = "!";

bot.on('ready', async () => {
console.log(`${bot.user.username} запустился`)
});

bot.on("messageCreate", function(message) {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;

const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();

if (command === "ping") {
const timeTaken = Date.now() - message.createdTimestamp;
message.reply(`Pong! This message had a latency of ${timeTaken}ms.`);
}

else if (command === "sum") {
const numArgs = args.map(x => parseFloat(x));
const sum = numArgs.reduce((counter, x) => counter += x);
message.reply(`The sum of all the arguments you provided is ${sum}!`);
}
});

bot.login('');
9 replies