discord.js - Imagine an appd-Iaa
discord.js - Imagine an appโ€ข3y agoโ€ข
21 replies
Midawek

So I've made a bot, but the command doesn't work, at least they don't get recognized. Any Ideas why?

const Discord = require('discord.js');
const token = 'token';
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});

function getQuote() {
    return fetch("https://zenquotes.io/api/random")
      .then(res => {
        return res.json()
        })
      .then(data => {
        return data[0]["q"] + " -" + data[0]["a"]
      })
  }


client.on('ready', () => {
    console.log(`Zalogowano jako ${client.user.tag}`);
});

client.on('message', async (message) => {
    if (message.content.startsWith('!addrole')) {
        //mention == good, so does role menu == good
        const user = message.mentions.user.first();
        const role_name = message.content.split(' ').slice(2).join(' ');

        if (!user || !role_name) {
            console.log('dum didnt mention use haha or didnt prov a rol')
            message.channel.send('pls mention user and prov a role name kthxbai')
            return;
        }
        

        // check if rol exists alr
        const role = message.guild.roles.cache.find((r) => r.name === role_name);
        
        if (!role) {
            console.log('alr found rol')
            message.channel.send('alr is a role you dumb idiot')
        }
        
        //add role :D
        const member = message.guild.members.cache.get(user.id);
        if (member) {
            member.roles.add(role)
            .then (() =>{
                console.log('add role ${role_name} to ${user.tag} hehe')
                message.channel.send('meh add role ${role_name} to ${user.tag} hehe')
            })
            .catch((error) => {
                console.error(error);
                message.channel.send('oopsie~! ewwow cawwed whiwe abbing fe wowe');
            })
        }
    }
})

client.on("message", msg => {
    if (msg.author.bot) return
      
    if (msg.content === "!inspire") {
      console.log('inspring imagination - roblox')
      getQuote().then(quote => msg.channel.send(quote))
    }
  })

 
client.login(token);
Was this page helpful?