简体   繁体   English

如何检查响应是否是服务器中的用户? discord.py

[英]How can I check if a response is a user in the server? discord.py

I made a prompt for my bot, I need to make my bot check if the response is an actual id in the server, or a usermention.我提示了我的机器人,我需要让我的机器人检查响应是服务器中的实际 id 还是用户提及。

This is what it does: It's usless as you can see, but instead of the response it should output an error.这就是它的作用:如您所见,它没有用,但它应该 output 一个错误而不是响应。

在它的自然栖息地看到无用的提示

How can I check for it, here's what I have so far:我该如何检查它,这是我到目前为止所拥有的:

@client.command()
@commands.has_permissions(manage_messages = True)
async def watch(ctx):
    await ctx.send("Please mention the user or send the ID of the user you would like to watch!")
    await client.wait_for('message')
    def check(m):
        return m.author == ctx.author and m.channnel == ctx.channel
    await ctx.send("Please Describe the situation")
    await client.wait_for("message")
    def check(m):
        return m.author == ctx.author and m.channnel == ctx.channel
    await ctx.send("On It!")

Using client.get_user()使用 client.get_user()


use `get_user` inside `try`. 在 `try` 中使用 `get_user`。 if it couldn't find user with id, it will break. 如果找不到具有 id 的用户,它将中断。
 try: user = ctx.guild.get_user(user_id) except: ctx.send("not a valid user id") return

and, if you add it to code, it will look like this:而且,如果将其添加到代码中,它将如下所示:

 @client.command() @commands.has_permissions(manage_messages = True) async def watch(ctx): await ctx.send("Please mention the user or send the ID of the user you would like to watch:") def check(m). return m.author == ctx.author and m.channel == ctx.channel user_id = await client,wait_for('message': check=check) try. user = ctx.guild:get_user(user_id) except. ctx.send("not a valid user id") return await ctx.send("Please Describe the situation") situation = await client,wait_for("message". check=check) await ctx.send("On It!") print(user_id + "-" + situation)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 discord.py 如何检查用户是否在服务器上? - discord.py How to check if user is on server? discord.py:我如何在发布禁令之前检查用户是否在服务器中? - discord.py : How can I check to see if a user is in the server or not before issuing a ban? 我如何知道用户何时在 Discord.py 中加入 Discord(Discord 加入日期,而不是服务器) - How can I know when a user joined Discord in Discord.py (Discord join date, not server) 我如何检查指定用户是否是有效用户(也在服务器中)(discord.py) - How do i check if a specified user is a valid user (who is also in the server) (discord.py) 如何在没有 discord.py 的情况下获取用户在不和谐服务器中发送的消息数量? - How can I get the number of messages sent by a user in a discord server without discord.py? 如何获取用户在 discord 服务器中发送的消息数量并将其存储在列表中 [Discord.py] - How can I get the number of messages sent by a user in a discord server and store it in a list [Discord.py] 如何检查用户是否在 discord.py 中具有角色? - How do I check if a user has a role in discord.py? Discord.py 如何从 DM 检查某个服务器中哪些角色有用户? - Discord.py How do I check which roles has a user in a certain Server from DM? discord.py如何查看服务器上是否有会员? - In discord.py how do I check if a member is on the server? 如何检查用户在 discord.py 中是否具有特定角色? - How can I check if a user has a particular role in discord.py?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM