我一直在开发一个 Discord selfbot,只是为了更好地学习discord.py,但我遇到了一个问题,我正在尝试这样做,以便如果我列入白名单的其他人将他们的 id 放入 .txt 文件中,他们可以运行命令例如,我将回复该命令的答案,
某人列入白名单:“+ping”
我:“乒乓球!”
这是我当前的代码:
client = discord.Client()
client = commands.Bot(command_prefix='+', self_bot=True,
fetch_offline_members=False)
def checkforuser(ctx):
return ctx.message.author.id == 669311027615105030
@client.command()
@commands.check(checkforuser)
async def ping(ctx):
await ctx.send('Pong!')
它不起作用,也没有错误,任何帮助将不胜感激:)
尝试使用
await ctx.send('Pong!')
而不是 ctx.send('Pong!')
。另外,您可以删除 client = discord.Client()
,因为您在下一行中为 client 定义了新值。
我正在为每个有这个具体问题的人撰写这个答案。
如果您不想手动执行此操作,我建议您创建命令将其他人列入白名单。
这是您的支票
def checkforuser(ctx: commands.Context):
"""
Returns True if the user appears to be found in the whitelist.txt
False if the user wasn't found in the whitelist.txt
"""
with open("whitelist.txt") as f:
user_ids = [int(line.strip("\n")) for line in f.readlines()]
return ctx.author.id in user_ids
open()
方法