抛出代码的代码块。
import discord
import os
import random
import sys
import RS9_List
from discord.ext import commands
from discord.utils import get
intents = discord.Intents().all()
intents.members=True
client = commands.Bot(command_prefix= '.', intents=intents)
fetch_offline_members = True
@client.command(aliases=['in9', 'In9', 'I9', 'i 9'])
async def i9(ctx):
if ctx.author==client.user:
return
await ctx.author.send('{ctx.author.display_name} Has Joined a Red Star 9 Que')
我已经被这个代码块困了 3 天了。我希望通过提及作者来获得命令 .i9 的回复。这是此代码将执行的第一步,我似乎无法让它工作。
我遇到的问题是,定义作者,定义成员,等等。我是编码新手,花了几天时间阅读文档。做练习代码,其他练习。我还是有问题。
任何帮助、资源、解决方案、洞察力等,我都很乐意敞开心扉接受。
我非常感谢您在这件事上花费的时间和投入。
Ignoring exception in command i9:
Traceback (most recent call last):
File "C:\Users\Mike\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Mike\Desktop\Discordbot\Seymourlist.py", line 36, in i9
await ctx.author.send('Joined Red Star 9-->{}'.format(message.author.name))
NameError: name 'message' is not defined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Mike\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Mike\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Mike\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'message' is not defined
答案 0 :(得分:1)
if ctx.author == client.user
没有意义,你可以试试:
async def i9(ctx):
await ctx.author.send(f'{ctx.author.display_name} Has Joined a Red Star 9 Que')