简体   繁体   中英

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.

This is what it does: It's usless as you can see, but instead of the response it should output an error.

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

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()


use `get_user` inside `try`. if it couldn't find user with id, it will break.
 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM