【问题标题】:Making !suggest command for my discord server, and need it to dm me, the owner. Is it possible to dm a specific person?为我的不和谐服务器制作 !suggest 命令,并需要它给我,所有者。可以dm特定的人吗?
【发布时间】:2020-07-14 19:11:32
【问题描述】:

所以我为我的不和谐服务器制作了一个 !suggest 命令,我已经完成了它,除非我需要它来向我发送该人提出的建议。我找不到有关如何通过 ID 或其他方式对特定人员进行 dm 的信息。到目前为止,这是我的编码命令:

async def suggest(server, suggestion):
    await server.owner.create_dm()
    await dm_channel.send("{} suggested this: '{}'".format(ctx.author.mention, suggestion))

请帮忙?

【问题讨论】:

    标签: python command bots discord discord.py


    【解决方案1】:

    您可以使用client.get_user 获取您自己的User 对象,该对象有一个send 方法,可以通过Discord 向您发送DM。

    from discord.ext import commands
    
    
    client = commands.Bot(command_prefix='!')
    
    
    @client.command()
    async def suggest(ctx, suggestion):
        dm_user = client.get_user(1234567890) # Your Discord ID here
        await dm_user.send("{} suggested this: '{}'".format(ctx.author.mention, suggestion))
    
    client.run('token')
    

    【讨论】:

    • 这会返回错误“discord.ext.commands.errors.CommandInvokeError: Command raise an exception: AttributeError: 'NoneType' object has no attribute 'send'”帮助?
    • 确保将 client.get_user(1234567890) 替换为 Discord 中您自己的用户 ID,否则将返回 None
    • 经过进一步研究,我已将代码更改为:@bot.command() async def suggest(ctx, suggestion): ch = client.get_channel(*i had the id here*) await ch.send("{} suggested {}".format(ctx.author.mention, suggestion)),但仍然返回相同的错误。它会将建议发送到我的私人建议频道,我可以在那里查看它。
    • get_channel 将返回该 ID 的频道,而不是用户。出于您的目的,您需要用户。使用您的代码和错误更新您的问题,以便对其进行审查
    猜你喜欢
    • 2018-07-21
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-25
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    相关资源
    最近更新 更多