【发布时间】:2021-07-31 17:32:03
【问题描述】:
我一直在研究这个机器人,当你输入“/court @user time”时,它会给他们角色 jail 并且在给定的时间后它将删除它但是当我运行它时它不起作用并且它说: “discord.ext.commands.errors.CommandInvokeError:命令引发异常:NameError:未定义名称'消息'”
import discord
from discord.ext import commands
import ctx
import re
import time
from time import sleep
PREFIX = "$"
bot = commands.Bot(command_prefix=PREFIX, description="Hi")
@bot.event
async def on_ready():
print('Logged on as', bot.user)
channel = bot.get_channel(717005397655027805)
#await channel.send("I am now online")
activity = discord.Game(name="eb!help", type=3)
await bot.change_presence(status=discord.Status.online, activity=activity)
@bot.command(name='court')
@commands.has_role('Server Developer')
async def court(ctx, user_mentioned, time):
messageContent = message.content
if len(messageContent) > 0:
if re.search("^send.*court$", messageContent):
user_id = message.mentions[0].id
user = message.mentions[0]
await message.channel.send(
f"sending <@{user_id}> to court!"
)
role = discord.utils.get(message.guild.roles, name="Jail")
await user.add_roles(role)
sleep(time)
await bot.remove_roles(user, role)
bot.run('TOKEN_GOES_HERE')
【问题讨论】:
-
错误很明显,您尝试访问
message,但您没有名为message的变量。
标签: python discord discord.py