【发布时间】:2023-01-22 21:26:52
【问题描述】:
我的 discord 机器人刚刚工作了一段时间,但突然间它无法识别频道中的命令。 该机器人拥有频道的管理员权限,之前可以发送消息。
机器人上线,令牌正常工作。
` 导入不和谐 随机导入 导入平台 导入操作系统 导入异步 从 discord.ext 导入任务、命令
intents = discord.Intents.default()
intents.messages = True
client = discord.Client(command_prefix=commands.when_mentioned_or('.'), intents=intents)`
quotes = ["quote 1 ", "quote 2",]
@client.event
async def on_ready() -> None:
print(f'{client.user} has connected to Discord!')
print(f"discord.py API version: {discord.__version__}")
print(f"Python version: {platform.python_version()}")
print(f"Running on: {platform.system()} {platform.release()} ({os.name})")
await update_status()
async def update_status():
while True:
await client.change_presence(status=discord.Status.online, activity=discord.Game(name="Deep Rock Galactic"))
await asyncio.sleep(10)
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content == ".quote":
print(message.author.id)
try:
quote = random.choice(quotes)
await message.channel.send(quote)
print("Executed command .quote")
except ValueError as e:
await message.channel.send(f'Command not working, reason: {e}')
if message.content == ".me":
print(message.author.id)
try:
if message.author.id == "author id:
quote = random.choice(quotes)
await message.channel.send(quote)
print("Executed command .me")
else:
await message.channel.send("Only user X can use this command")
except ValueError as e:
await message.channel.send(f'Command not working, reason: {e}')
client.run("TOKEN")`
更改了令牌,删除了 .me 功能并在没有它的情况下进行了尝试。
【问题讨论】:
标签: python discord discord.py command bots