家齐高中资讯研究社 社课内容2

基本建置

1.discord 开发者介面里点取newapplication
2.在Bot上点取AddBot
3.然后点在OAUth点SCOPES里面的bot,下面即会有一串网址
4.再来只要把网址贴上,选择你要的伺服器即可
此外 机器人名字近量不要取太常见的名子
http://img2.58codes.com/2024/20142610w5t0bIkHJ0.png

http://img2.58codes.com/2024/20142610qCDQCLUtvI.png

http://img2.58codes.com/2024/201426103WF7EjV5VQ.png

http://img2.58codes.com/2024/20142610UdV6yjoz6g.png

基本程式码

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
http://img2.58codes.com/2024/20142610YO1UnbUjjb.png

@bot.command                   #可把图片网址放上来  执行此指令即可跑出图片async def web1(ctx):    random_pic1 = "网址"    await ctx.send(random_pic1)

ctx
上下文

A:嘿 上文 (使用者,id,所在频道,所在伺服器)B:嗨 下文

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章