[Python]vxtwitterへの変更 bot
1.ライブラリ
discord.py
pip install -U discord.py
2.コード
コピーしても使える物です。
import discord, asyncio, re
from discord.ext import commands
client = commands.Bot(command_prefix=".", intents=discord.Intents.all())
@client.event
async def on_ready():
await client.tree.sync()
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="im8ru"))
print ("Success : Bot is connected to Discord.")
@client.event
async def on_message(message):
if message.author == client.user:
return
replaced_message = re.sub(r'https?://(twitter\.com|x\.com)/', 'https://fxtwitter.com/', message.content)
if replaced_message != message.content:
await message.channel.send(f'replaced: {replaced_message}')
async def main():
async with client:
await client.start("TOKEN")
asyncio.run(main())
3.使用例
![](https://assets.st-note.com/img/1705236258323-Zx7A5XhQ5u.png?width=1200)