- Go to the Discord Developer Portal
- Click "New Application" and name your bot
- Go to the "Bot" tab
- Under the Token section:
- Click "Reset Token" if not yet generated
- Click "Copy" to get your bot token (you'll add this to the
.env
file)
- Scroll down and enable "Message Content Intent" under Privileged Gateway Intents
- Go to the "OAuth2" tab:
- Select "bot" under scopes
- For permissions, select:
- Embed Links
- Read Messages/View Channels
- Send Messages
- Use the generated URL to add the bot to your server
- Sign up for a Twitter Developer account at developer.twitter.com
- Create a new project and app
- Generate API keys and tokens
- Find your Twitter user ID:
- Use a tool like tweeterid.com
- Or run the script:
node getTwitterUserId.js
-
Create a new folder for your project
-
Install required packages:
npm init -y npm install discord.js twitter-api-v2 dotenv
-
Get Discord Channel ID
- Open Discord
- Go to User Settings (⚙️ gear icon next to your username)
- Scroll down to Advanced
- Enable Developer Mode
- Right-click on the channel where you want to post tweets
- Click "Copy Channel ID"
- Paste it into your
.env
file
-
Create a
.env
file and add your credentials:DISCORD_CHANNEL_ID=your_discord_channel_id DISCORD_TOKEN=your_discord_bot_token TWITTER_USERNAME=your_twitter_username TWITTER_USER_ID=your_twitter_user_id TWITTER_API_KEY=your_twitter_api_key TWITTER_API_SECRET=your_twitter_api_secret TWITTER_ACCESS_TOKEN=your_twitter_access_token TWITTER_ACCESS_SECRET=your_twitter_access_secret
node index.js
- Keep your
.env
file secure and never share your tokens - Make sure to add
.env
to your.gitignore
file - The bot requires Node.js version 16.0.0 or higher
- https://railway.com is a great place to host your bot for free