这是我的第一个代码
# IMPORT
import discord
from discord.ext import commands
import os
# INIT
client = commands.Bot(command_prefix = '.')
@client.command()
async def load(ctx, extension):
client.load_extension(f'cogs.{extension}')
@client.command()
async def unload(ctx, extension):
client.unload_extension(f'cogs.{extension}')
@client.command()
async def reload(ctx, extension):
client.unload_extension(f'cogs.{extension}')
client.load_extension(f'cogs.{extension}')
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
client.run('My Token)
这是我的第二个密码
# IMPORT
import discord
from discord.ext import commands
# INIT
class Admin(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_member_join(self, member):
print(f'{member} has joined a server')
@commands.Cog.listener()
async def on_member_remove(self, member):
print(f'{member} has left a server')
@commands.command(aliases=['cls'])
@commands.has_permissions(kick_members=True)
async def clear(self, ctx, amount=20):
await ctx.channel.purge(limit=amount)
await ctx.send("Refreshing channel")
@commands.command()
@commands.has_permissions(kick_members=True)
async def kick(self, ctx, member : discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.send(f'Banned {member.mention}')
@commands.command()
@commands.has_permissions()
async def ban(self, ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'Banned {member.mention}')
def setup(client):
client.add_cog(Admin(client))
因此,我已经运行了第一个代码,然后我尝试使用我的一个alt帐户进行测试,但是 不知何故,代码不起作用
我试着运行.ban,但它没有做任何事情,我也已经检查了控制台/cmd,但我没有看到任何错误
Python版本:3.8.3, Discord.py 1.4.1
ctx
位于self
之后,在代码中,您在member
参数之后传递ctx
你在这一行也有一个打字错误:
相关问题 更多 >
编程相关推荐