本文介紹了Discord.py rewrite 如何 DM 命令?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我試圖讓我的機器人在執行-help"時向用戶發送幫助.
I am trying to have my bot DM the user the help when "-help" is executed.
我已經嘗試在我的代碼中執行此操作,但它不起作用.
I have tried doing this in my code already but it will not work.
async def help(ctx):
helpembed = discord.Embed(color=discord.Color.purple())
helpembed.set_author(name="Help")
helpembed.add_field(name="-new", value="Creates a new ticket. [Logged]",inline=False)
helpembed.add_field(name="-close", value="Closes the ticket.People with the role 'Viewing Team' can close ticets. [Logged]",inline=False)
helpembed.add_field(name="-setup", value='Sets Up your server so it can be used',inline=False)
helpembed.add_field(name="-help", value="Shows this message :rofl:",inline=False)
await client.send_message(ctx.message.author, embed=helpembed)
await ctx.send("Help sent in DM's.")```
The bot should DM the user with help. Instead it does nothing.
推薦答案
向discord.py-rewrite,你使用 User.send
方法:
To send a private message to a user in discord.py-rewrite, you use the User.send
method:
async def help(ctx):
...
await ctx.author.send(...)
這是因為 User
是抽象 Messageable
類
This is because User
is a subclass of the abstract Messageable
class
這篇關于Discord.py rewrite 如何 DM 命令?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!