@bot.command()
async def hello(ctx):
await ctx.send(f"!Hi <@{ctx.author.id}>")
ctx是一种引数,且ctx是context(上下文的缩写)
author是本人,今天我在上头打了hello,机器人便会回覆加上@自己* 接着来看一下 author.id
因为我要@自己,所以是用author,当然,你也可以指定某人就是了(id: int)
async跟await同一家族的(当然还有asyncio......之类的)
这里是官方的解释
我们使用purge来删除留言
@bot.command()
async def clear(ctx, num:int):
await ctx.channel.purge(limit = num+1)
@bot.event
async def on_member_join(member):
await self.bot.get_channel(idchannel).send(f"{ member.name } has joined")
@bot.event
async def on_member_remove(member):
await self.bot.get_channel(idchannel).send(f"{ member.name } has left")
# 刚刚我们写到能使用bot、第一个指令
# 还有添加了json
bot = commands.Bot(command_prefix = '!',
owner_ids = data['owner_id'],
intents = discord.Intents.all())
这边的owner_id是你自己(创作者)的ID
之後,我们引用os函式库
import os
# 只要是python档案就会进行载入
for file in os.listdir("cogs"):
if file.endswith(".py"):
name = file[:-3]
bot.load_extension(f"cogs.{name}")
# core/any.py
import discord
from discord.ext import commands
# 这边可以使用Cog功能继承基本属性
class Cog_Extension(commands.Cog):
def __init__(self, bot):
self.bot = bot
# cogs/hello.py
from discord.ext import commands
import discord
from discord.ext.commands import bot
from core.any import Cog_Extension
class Hello(Cog_Extension):
@commands.command()
async def hello(self, ctx):
await ctx.send(f"!Hi <@{ctx.author.id}>")
def setup(bot):
bot.add_cog(Hello(bot))
>>: Day13:[解题技巧]Two pointers - 双指针
该文章同步发布於:我的部落格 After Hooks 之前有介绍过 before hooks 的使...
接下来照着永丰提供的github, 下一个要使用到的是快照-Snapshot的部分, 简单来说就是当...
-NIST SDLC 和 RMF -认证和认可 (C&A) -授权决定 认证(Certif...
iOS APP 开发 OC 第十四天,签证 tags: OC 30 day 资料来源:iOS 打包签...
NACL vs SG 的安全设定介绍 当请求想进出在 Private Subnet 内的 EC2 ...