【问题标题】:Discord.py how to get bot to print out how many members it has? Also, how do I get my bot to get what a user has said?Discord.py 如何让机器人打印出它有多少成员?另外,我如何让我的机器人获取用户所说的内容?
【发布时间】:2018-06-11 22:42:33
【问题描述】:

所以,我希望我的机器人打印出我的服务器中的成员数量。我一试就明白了:

Counter Top MTG has this amount of members: <property object at 0xb6a48e14>

我的代码是:

@client.command()
async def report():
    x = server.Server.members
    await client.say("`Counter Top MTG has this amount of members: {}`".format(x))

我的第二个问题:

所以,我想做一个报告方法,让用户说:

!report bob cheated in life

它会获取该信息并将其发送给我。我不知道从哪里开始。

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    您传递命令的上下文,从中获取Server 对象,然后使用该信息进行响应:

    @client.command(pass_context=True)
    async def report(ctx):
        await client.say("`{0.name} has this amount of members: {0.member_count}`".format(ctx.message.server))
    

    要PM自己,必须先获取代表你的User对象,然后使用send_message

    @client.command(pass_context=True)
    async def report(ctx, *, message):
        me = await client.get_user_info("Your User ID")
        pm = "{} reported: {}".format(ctx.message.author, message)
        await client.send_message(me, pm)
    

    这需要您知道您的 Discord ID。关注these steps获取。

    【讨论】:

    • 谢谢!如何获取向我发送报告的用户名?
    • @asdwdwdad ctx.message.author.name
    • 我将如何制作它以便它在下午发送它?
    • 然后呢?我不知道该怎么做,所以它会在下午发送它?
    猜你喜欢
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 2021-10-02
    • 1970-01-01
    • 2020-08-17
    • 2018-05-10
    相关资源
    最近更新 更多