Hiện Telegram đã bị chặn, mình sẽ viết 1 bài hướng dẫn các bạn tạo Bot và gửi tin trên Discord thay thế nền tảng Telegram.
Bước 1: Bạn cần tạo 1 tài khoản trên https://discord.com
Bước 2: Tạo Máy chủ Của Bạn (Group) Sau khi hoàn tất việc xác thực tài khoản, bạn truy cập https://discord.com và thực hiện tạo một máy chủ mới, thực hiện đặt tên máy chủ.
Bước 3: Tạo bot trong Discrod Developer Portal
3.1 Vào trang: https://discord.com/developers/applications
3.2 Nhấn "New Applicaiton" -> Đặt tên -> Create
Sau khi bấm Create xong, bạn sẽ được chuyển đến màn hình quản lý Application vừa tạo
Bước 4: Mời bot vào server Discord của bạn
4.1 Tạo URL Generator
Vào tab OAuth2 -> OAuth2 URL Generator
- Scopes -> Chọn Bot
- Bot Permissions -> Chọn Send Messages, Read Message History
4.2 Copy Link ở Generated URL
Copy link mở trong trình duyệt -> Chọn server để mời bot
Bước 5: Lấy thông tin TOKEN của bot
Vào tab Bot -> Chọn TOKEN -> Chọn Reset Token
Bước 6: Code python send notify
# pip install discord.py # cài thư viện discord
import discord
import asyncio def send_discord_bot_message(token: str, channel_id: int, message: str): class MyClient(discord.Client): async def on_ready(self): print(f"🤖 Bot đã đăng nhập: {self.user}") channel = self.get_channel(channel_id) await channel.send(message) print(f"✅ Đã gửi tin nhắn tới channel {channel_id}") await self.close() # tự động đóng connection đúng cách intents = discord.Intents.default() client = MyClient(intents=intents) client.run(token) # Token bot và ID channel của bạn
TOKEN = "Token lấy ở bước 5" # Alert
CHANNEL_ID = 1376449208634179586 # thay bằng ID thực tế send_discord_bot_message(TOKEN, CHANNEL_ID, "📢 Hello, đây là bot gửi tin nhắn!")
Kết quả:
Chúc các bạn làm thành công