DLTC Bot
DLTC市場情報を表示するBot
ENV
.env.example
DISCORD_TOKEN=
DWALLET_API_KEY=
DWALLET_BASE_URL=https://dwallet-api.nikoroyal.com
TEXT
requirements.txt
discord.py>=2.5
dwsdk>=2.0.0
python-dotenv>=1.0
PYTHON
bot.py
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
from dwallet import DWalletClient
load_dotenv()
TOKEN = os.environ["DISCORD_TOKEN"]
class Bot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!", intents=discord.Intents.default())
self.dw = DWalletClient.from_env()
async def setup_hook(self):
await self.dw.__aenter__()
await self.tree.sync()
async def close(self):
await self.dw.close()
await super().close()
bot = Bot()
@bot.tree.command(name="dltc", description="DLTC情報を表示します")
async def dltc(interaction: discord.Interaction):
market = await bot.dw.dltc_market(interval="5m", limit=20)
balance = await bot.dw.for_user(interaction.user.id).dltc_balance()
s = market["snapshot"]
embed = discord.Embed(title="DLTC")
embed.add_field(name="価格", value=f"`¥{s['market_price_jpy']}`", inline=False)
embed.add_field(name="残高", value=f"`{balance['available']} DLTC`", inline=False)
embed.add_field(name="時価総額", value=f"`¥{market['market_cap_jpy']}`", inline=False)
await interaction.response.send_message(embed=embed, ephemeral=True)
bot.run(TOKEN)
