基本建置
1.discord 开发者介面里点取newapplication
2.在Bot上点取AddBot
3.然后点在OAUth点SCOPES里面的bot,下面即会有一串网址
4.再来只要把网址贴上,选择你要的伺服器即可
此外 机器人名字近量不要取太常见的名子
基本程式码
import discord #导入discordfrom discord.ext import commands bot=commands.Bot(command_prefix="*") #呼叫discord机器人前的要加的咚咚@bot.eventasync def on_ready(): #此为异步协成 这边就不多作介绍了,有兴趣的可上网学 print(">>Bot is online<<") bot.run("token") #token 可在discord开发者页面 点一下Bot 就可以看到了
@bot.eventasync def on_member_join(member): channel = self.bot.get_channel(channel id) await channel.send(f"{member} join!")@bot.eventasync def on_member_leave(member): channel = self.bot.get_channel(channel id) await channel.send(f"{member} leave!")
channel id可在使用者介面开启后,进阶那有个开发者介面,打开后,可在频道旁按右键获得id
@bot.command #可把图片网址放上来 执行此指令即可跑出图片async def web1(ctx): random_pic1 = "网址" await ctx.send(random_pic1)
ctx
上下文