python - 如何定义“@client.command”?
问题描述
所以基本上我有这个代码:
import discord
import os
bot = commands.Bot(command_prefix = "!")
TOKEN = (os.getenv("TOKEN"))
client = discord.Client()
@client.event
async def on_message(message):
if message.content.startswith('!help'):
embedVar = discord.Embed(
title="Help Page", description="Under development", color=0x00ff00)
await message.channel.send(embed=embedVar)
@client.command()
@commands.has_any_role("Owner")
async def ban (ctx, member:discord.User=None, reason =None):
if member == None or member == ctx.message.author:
await ctx.channel.send("You cannot ban yourself")
return
if reason == None:
reason = "Breaking Rules"
message = f"You have been banned from {ctx.guild.name} for {reason}"
await member.send(message)
# await ctx.guild.ban(member, reason=reason)
await ctx.channel.send(f"{member} is banned!")
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
当我运行它时,我得到了后续错误:
Traceback (most recent call last):
File "main.py", line 4, in <module>
bot = commands.Bot(command_prefix = "!")
NameError: name 'commands' is not defined
有人可以帮帮我吗?
解决方案
在命令文档中,它声明将其添加到您的导入中:
from discord.ext import commands
推荐阅读
- dataframe - 在 Julia 的绘图函数中使用运算符
- javascript - 渲染期间运行的 useMemo 函数
- flutter - 堆栈小部件在 SCSV、颤振中不滚动
- javascript - 被 res.writeHead 301 nextjs 重定向后无法返回
- python - 使用 Python 从 Qlik API 中提取数据
- spring - 定义多级 spring application.yml 层次结构
- mysql - 根据不同关联模型的计数对模型进行排序
- python - Selenium Python 目标 Mailinator 窗口视图
- python - 如何使用 Pandas 和 tabula-py 从一个 PDF 文件中提取多个表格
- wordpress - 我怎样才能找到这个元素在哪里生成来改变方向?