【问题标题】:How to make my custom discord bot sends message如何让我的自定义不和谐机器人发送消息
【发布时间】:2020-12-26 16:01:17
【问题描述】:

我试图让我的自定义机器人使用 python 发送自定义消息

我:~重复嗨

我的消息已删除

自定义机器人:嗨

每当我尝试使用此代码时,我都会遇到此代码的错误问题,特别是“客户端”

等待客户端.delete_message(ctx.message)

return await client.say(mesg)

from discord.ext import commands 

client = commands.Bot(command_prefix = '~') #sets prefix 

@client.command(pass_context = True)
async def repeat(ctx, *args):
    mesg = ' '.join(args)
    await client.delete_message(ctx.message)
    return await client.say(mesg)

client.run('Token')

【问题讨论】:

标签: python python-3.x discord discord.py


【解决方案1】:

client没有delete_message的属性,删除作者的消息使用ctx.message.delete。要在 discord.py 的 rewrite 分支中发送消息,请使用 await ctx.send()

@client.command()
async def repeat(ctx, *args):
    await ctx.message.delete()
    await ctx.send(' '.join(args))

【讨论】:

    猜你喜欢
    • 2021-04-25
    • 2019-07-11
    • 2021-01-19
    • 2021-08-07
    • 1970-01-01
    • 2020-09-06
    • 2021-05-30
    • 2021-04-07
    • 1970-01-01
    相关资源
    最近更新 更多