【发布时间】:2021-12-18 13:21:29
【问题描述】:
Discord.py 的代码中有一个“意外的缩进”,代码是:
@client.command()
async def kick(ctx, member: discord.Member, reason=None):
await member.kick(reason=reason)
await ctx.send("The Member Was Kicked.")
完整代码:
import os
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord.ext.commands import has_permissions, MissingPermissions, is_owner
import json
client = commands.Bot(command_prefix='.')
status=discord.Status.idle
@client.command()
async def ban(ctx, member: discord.Member, reason=None):
await member.ban(reason=reason)
await ctx.send("The Member Was Banned.")
@client.command()
async def kick(ctx, member: discord.Member, reason=None):
await member.kick(reason=reason)
await ctx.send("The Member Was Kicked.")
@client.event
async def on_ready():
print('we have logged in as {0.user}'.format(client))
my_secret = os.environ['Token']
client.run(my_secret)
【问题讨论】:
-
您的
@client.command()显然缩进不正确。它应该与下一行的async def kick(ctx, member: discord.Member, reason=None):处于相同的缩进级别。 -
第一个sn-ps和第二个sn-ps的缩进不同,需要打个minimal reproducible example
标签: python discord discord.py