Search code examples
javascriptnode.jsdiscorddiscord.jsbots

How can I send message or do something in a specific discord server using discord.js?


How can I send a message or assign a role on a specific discord server from the discord server's Id?

(My goal is to make a discord bot and when someone does something in my website, it will give a api call to my discord.js and it will give a role in the specific discord server he/she selected.)

I just wanted to do https://discord.com/developers/docs/resources/guild#add-guild-member-role this in discord.js. But it seems like discord.js adds role to the server where an event ran.


Solution

  • Sorry if it's not what you want, I don't have a lot of informations

    it will be anything like that:

    const guild = client.guilds.cache.get("GUILD ID")
    if (!guild) return;
    
    guild.members.cache.get("member id")
    if (!member) return;
    
    guild.roles.cache.get("role id")
    if (!role) return;
    
    member.roles.add(role)