Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
Discord bot
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Khalil" data-source="post: 453393" data-attributes="member: 9938"><p>This can easily be achieved using OAuth and a bot with access to your database.</p><p></p><p>The process would be as such:</p><p>- Have the user authenticate through Discord's OAuth service while their session is active on your website.</p><p>- Grab their Discord ID following the authentication process and add it to their user information.</p><p>- Grant the bot access to your database, the point at which it would look for a Discord ID upon a new server join, match it to an existing user on your server and change their nickname to correspond with their username.</p><p></p><p>The implementation would roughly look something like this:</p><p>[CODE=coffeescript]</p><p>MySQL = require "mysql"</p><p>Discord = require "discord.js"</p><p></p><p># This database has to be the same one you're using for your website.</p><p>Connection = MySQL.createConnection { host: "localhost", user: "something", password: "something", database: "database" }</p><p>Client = new Discord.Client</p><p></p><p>Client.on "ready", () -></p><p> console.log "Client logged on as " + Client.user.username + "#" + Client.user.discriminator</p><p></p><p># The bot would listen for new users.</p><p>Client.on "guildMemberAdd", (Member) -></p><p> # We check to see if the new user's ID exists in our records.</p><p> Connection.query "SELECT * FROM users WHERE discord_id = ?", [Member.id], (Error, Rows) -></p><p> if (Error)</p><p> throw Error</p><p></p><p> # Found them.</p><p> if Rows.length</p><p> # Check if the bot has permission to change other users' nicknames.</p><p> if Member.guild.me.hasPermission ["MANAGE_NICKNAMES"]</p><p> # Change their nickname to correspond with their existing username on your database.</p><p> Member.setNickname Rows[0].username</p><p></p><p> Connection.end</p><p> </p><p>Client.login "YOUR BOT TOKEN"</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="Khalil, post: 453393, member: 9938"] This can easily be achieved using OAuth and a bot with access to your database. The process would be as such: - Have the user authenticate through Discord's OAuth service while their session is active on your website. - Grab their Discord ID following the authentication process and add it to their user information. - Grant the bot access to your database, the point at which it would look for a Discord ID upon a new server join, match it to an existing user on your server and change their nickname to correspond with their username. The implementation would roughly look something like this: [CODE=coffeescript] MySQL = require "mysql" Discord = require "discord.js" # This database has to be the same one you're using for your website. Connection = MySQL.createConnection { host: "localhost", user: "something", password: "something", database: "database" } Client = new Discord.Client Client.on "ready", () -> console.log "Client logged on as " + Client.user.username + "#" + Client.user.discriminator # The bot would listen for new users. Client.on "guildMemberAdd", (Member) -> # We check to see if the new user's ID exists in our records. Connection.query "SELECT * FROM users WHERE discord_id = ?", [Member.id], (Error, Rows) -> if (Error) throw Error # Found them. if Rows.length # Check if the bot has permission to change other users' nicknames. if Member.guild.me.hasPermission ["MANAGE_NICKNAMES"] # Change their nickname to correspond with their existing username on your database. Member.setNickname Rows[0].username Connection.end Client.login "YOUR BOT TOKEN" [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Discord bot
Top