📝Introduction
Tweetcord is a discord bot that uses the tweety-ns module to let you receive tweet updates from specific Twitter users on discord. You just need to set up the Twitter users and discord channels you want to follow, and Tweetcord will automatically send the tweets to the designated channels, so you won’t miss any important news.🐦
✨Features
Screenshots
👇When the followed user posts a new tweet, your server will also receive a notification.
Commands
👉 /add notifier
username
channel
| mention
parameters | types | descriptions |
---|---|---|
username |
str | The username of the twitter user you want to turn on notifications for |
channel |
discord.TextChannel | The channel to which the bot delivers notifications |
mention |
discord.Role | The role to mention when notifying |
👉 /remove notifier
username
channel
parameters | types | descriptions |
---|---|---|
username |
str | The username of the twitter user you want to turn off notifications for |
channel |
discord.TextChannel | The channel which set to delivers notifications |
👉 /list users
- List all twitter users whose notifications are enabled on the current server
📥Installation
Before running the bot, you need to install the necessary modules.
pip install -r requirements.txt
In certain operating systems, you may need to use the command pip3
instead of pip
for installation.
⚡Usage
📢This tutorial is suitable for version 0.3.2 or later. (Recommended: 0.3.5 or later)
📌click here to upgrade from 0.3.4 to 0.3.5
Create a python file in the cogs
folder and name it upgrade.py
. Paste the following code and run the bot. Use the slash command /upgrade
to upgrade. This cog can be removed after the upgrade is completed.
import discord
from discord import app_commands
from core.classes import Cog_Extension
import sqlite3
import os
from src.log import setup_logger
from src.permission_check import is_administrator
log = setup_logger(__name__)
class Upgrade(Cog_Extension):
@is_administrator()
@app_commands.command(name='upgrade', description='upgrade to Tweetcord 0.3.5')
async def upgrade(self, itn: discord.Interaction):
await itn.response.defer(ephemeral=True)
conn = sqlite3.connect(f"{os.getenv('DATA_PATH')}tracked_accounts.db")
cursor = conn.cursor()
cursor.executescript('ALTER TABLE channel ADD server_id TEXT')
cursor.execute('SELECT id FROM channel')
channels = cursor.fetchall()
for c in channels:
try:
channel = self.bot.get_channel(int(c[0]))
cursor.execute('UPDATE channel SET server_id = ? WHERE id = ?', (channel.guild.id, channel.id))
except:
log.warning(f'the bot cannot obtain channel: {c[0]}, but this will not cause problems with the original features. The new feature can also be used normally on existing servers.')
conn.commit()
conn.close()
await itn.followup.send('successfully upgrade to 0.3.5, you can remove this cog.')
async def setup(bot):
await bot.add_cog(Upgrade(bot))
📌click here to upgrade from 0.3.3 to 0.3.4
Because the database structure has been updated, you must use the following code to update the database structure.
from dotenv import load_dotenv
import os
import sqlite3
load_dotenv()
conn = sqlite3.connect(f"{os.getenv('DATA_PATH')}tracked_accounts.db")
cursor = conn.cursor()
cursor.execute('ALTER TABLE notification ADD enabled INTEGER DEFAULT 1')
conn.commit()
conn.close()
1. Create and configure the .env file
BOT_TOKEN=YourDiscordBotToken
TWITTER_TOKEN=YourTwitterAccountAuthToken
DATA_PATH=./data/
You can retrieve your auth token from cookies, or you can explore other methods to obtain it.
2. Configure the configs.yml file
All time-related configurations are measured in seconds.
prefix: '' # The prefix for bot commands.
activity_name: '' # The activity name displayed by the bot.
tweets_check_period: 10 # The check frequency for the posts (it is not recommended to set this value too low to avoid rate limiting).
tweets_updater_retry_delay: 300 # Retry Interval when Tweets Updater encounters exceptions (e.g., rate limitations).
tasks_monitor_check_period: 60 # Interval at which to check if each tasks is functioning properly, and if a task has stopped, attempt a restart.
tasks_monitor_log_period: 14400 # Interval at which to output the list of currently running tasks to the execution log.
3. Run and invite the bot to your server
python bot.py
In certain operating systems, you may need to use python3
instead of python
.
🔧Bot Permissions Setup 2147666944
- Read Messages/View Channels
- Send Messages
- Embed Links
- Attach Files
- Mention Everyone
- Use Slash Commands
4. Have fun
Now you can go back to Discord and use the /add notifier
command to set up notifications for the Twitter users you wish to receive updates from!
💪Contributors
This project exists thanks to all the people who contribute.