所以,我对此很新(目前已有30分钟的经验)并试图让我的Discord机器人在使用一个命令选项时显示一条消息。但它只是不起作用。
async def cmd_warn(self, message, user_mentions, option):
"""
Usage:
{command_prefix}warn [ spam | racism | discrimination | inappropriate | inpersonating | arguing | rudeness | harassment ] @UserName [@UserName2 ...]
Warn users for spam / racism / discrimination / inappropriate / inpersonating / arguing / rudeness / harassment
"""
if not user_mentions:
raise exceptions.CommandError("**Error:** No users listed.", expire_in=20)
if option not in ['spam', 'racism', 'discrimination', 'inappropriate', 'inpersonating', 'arguing', 'rudeness', 'harassment']:
raise exceptions.CommandError(
'**Invalid reason:** Use !help warn for more info!' % option, expire_in=20
)
for user in user_mentions.copy():
if user.id == self.config.owner_id:
print("[Commands:Warn] The owner cannot be warned (Tyler rigged).")
user_mentions.remove(user)
old_len = len(self.blacklist)
if option in ['spam']:
return Response('( %s ) You were warned for spam!')
)
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.command(pass_context=True):
async def warn(ctx, option, *members: discord.Member):
if not members:
raise commands.CommandError('Must mention at least one user')
if option.lower() not in ['spam', 'racism', 'discrimination', 'inappropriate',
'inpersonating', 'arguing', 'rudeness', 'harassment']:
raise commands.CommandError('Invalid reason: {}'.format(option))
for member in members:
if member.id == config.owner_id:
print('Owner cannot be warned')
else:
await bot.say('{} you have been warned for {}'.format(member.mention, option))
这是您要完成的基本版本。请注意,CommandError
位于discord.ext.commands
模块中。我也在这里直接与频道互动。
我鼓励你尽可能切换到重写分支,只因为它有异步分支缺少的documentation for the commands
extension。