@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
# can be cached...
me = await client.get_user_info('MY_SNOWFLAKE_ID')
await client.send_message(me, "Hello!")
@client.event
async def on_message(message):
if message.content.startswith("#whatever you want it to be")
await client.send_message(message.author, "#The message")
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
@bot.command()
async def suggest(ctx, *, text: str):
me = bot.get_user(YOUR_ID)
await me.send(text) # or whatever you want to send here
带on_message:
from discord.ext import commands
bot = commands.Bot()
@bot.event
async def on_message(message: discord.Message):
if message.content.startswith("!suggest"):
text = message.content.replace("!suggest", "")
me = bot.get_user(YOUR_ID)
await me.send(text) # or whatever you want to send here
4条答案
按热度按时间pw136qt21#
您必须使用
send_message
方法。在此之前,你必须找到哪个User
对应于你自己。rpppsulh2#
用你想要的单词替换那些带标签的东西。例如:“无论你想成为什么,它都可能是”!#消息可以是“命令是...”。
lyr7nygr3#
对于任何新的:
格式:
on_message:
命令示例1:
命令示例二:
xmd2e60i4#
discord.py v1.0.0+
从v1.0.0开始,不再使用
client.send_message
发送消息,而是使用abc.Messageable
的send()
,它实现了以下内容:discord.TextChannel
discord.DMChannel
discord.GroupChannel
discord.User
discord.Member
commands.Context
示例
使用
bot.command()
(推荐):带
on_message
: