DiscordBot / bot_main.py
MKE0108's picture
merge
729b742
raw
history blame
2.03 kB
import discord
from discord.ext import commands
import os
if(os.getenv('BOT_TOKENS') == None):
from keys import init
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'{bot.user} 已連線到 Discord!')
@bot.command()
async def synccommands(ctx):
await bot.tree.sync()
await ctx.send('同步完成')
@bot.hybrid_command(description="這個指令會回覆你的問候")
async def hello(ctx):
await ctx.send(f'你好 {ctx.author.name}!')
@bot.hybrid_command(description="測試延遲")
async def ping(ctx):
await ctx.send(f'Pong! 延遲: {round(bot.latency * 1000)}ms')
@bot.hybrid_command(description="顯示機器人資訊")
async def info(ctx):
embed = discord.Embed(title="機器人資訊", color=0x00ff00)
embed.add_field(name="名稱", value=bot.user.name, inline=True)
embed.add_field(name="ID", value=bot.user.id, inline=True)
embed.add_field(name="伺服器數量", value=len(bot.guilds), inline=True)
await ctx.send(embed=embed)
@bot.hybrid_command(description="抽路線指令, 用法: !pick 人名1 人名2 人名3 ...")
async def pick(ctx,str):
import random
player = str.split(' ')
if(len(player) > 5):
await ctx.send('請輸入<5個人')
return
lane=["🗡️ 上路","💰 打野","🔮 中路","🏹 下路","🚑 輔助"]
while(len(player) < 5):
player.append("---")
random.shuffle(player)
embed = discord.Embed(title="抽獎結果", color=0x00ff00)
for i in range(len(player)):
embed.add_field(value=player[i], name=lane[i], inline=False)
solgan = ["我從不覺得在召喚峽谷快樂過","一但加入了召喚峽谷就再也回不去了","我們的遊戲就是要讓你們不開心","你們的不開心就是我們的快樂","你們滿腦子只想著自己","還真是虛情假義呢"]
await ctx.send(random.sample(solgan,1)[0],embed=embed)
bot.run(os.getenv('BOT_TOKENS'))