嘿嘿嘿
pip install discord.py
reset token 之後複製
import discord
from discord.ext import commands
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix="你想要的符號",intents = intents)
bot.run("TOKEN")
@bot.event
async def on_ready(): #開機會觸發
print(f'The bot has been log in as {bot.user}')
game = discord.Game("狀態")
await bot.change_presence(status=discord.Status.online, activity=game)
@bot.event
async def on_member_join(member):
channel = bot.get_channel(your channel id)
await channel.send(f'{member}join!')
@bot.event
async def on_member_remove(member):
channel = bot.get_channel(your chnne id)
await channel.send(f'{member}leave!')
@bot.command()
async def ping(ctx):
await ctx.send(f'{round(bot.latency*1000)}(ms)')
@bot.command()
async def clear(ctx, num:int):
await ctx.channel.purge(limit = num+1)
@bot.listen()
async def on_message(msg):
if msg == '判斷的字串':
await msg.channel.send('輸出')
@bot.command()
async def clear(ctx, num:int):
await ctx.channel.purge(limit = num+1)
指的是上下文 可以知道上文輸入的資訊
(id, 頻道之類的東西)
下禮拜教slash command