簡體   English   中英

檢查消息是否由 DM (discord.py) 中的用戶發送,然后將他們的消息從直接消息發送到某個頻道?

[英]Check if a message was sent by a user in a DM (discord.py) then send their message from a direct message into a certain channel?

msg_dump_channel = 1234
@bot.event
async def on_message(message: discord.Message):
    channel = bot.get_channel(msg_dump_channel)
    if str(message.author) == "user":
        await channel.send(message.content)
    await bot.process_commands(message)

這是我的代碼,我知道DM沒有公會,那么你會如何為DM編寫它?

discord.Message對象具有可用於檢查的channel屬性:

@bot.event
async def on_messsage(message)
    if isinstance(message.channel, discord.DMChannel) and str(message.author) ==  'user':
        channel = bot.get_channel(channel_id)
        await channel.send(message.content)
    else:
        pass

    bot.process_commands(message)
        

這應該是一個例子

@bot.event
async def on_message(message)
guild = message.guild
if not guild:
    print(" DM: {0.author.name} : {0.content}".format(message))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM