python - message.channel.id Discord PY

标签 python python-3.x discord.py

我正在尝试创建一个日志机器人,但是我遇到了 message.channel.id 问题

事件触发时发送的内容; 消息 ID - 消息 ID |用户 - 用户 ID |他们的讯息 |我的私有(private)日志 channel - 他们发送消息的服务器

代码的预期应用; 消息 ID - 消息 ID |用户 - 用户 ID |他们的讯息 |他们发送消息的服务器 - 他们发送消息的服务器

@bot.event
async def on_message(message):
    user = message.author
    user_id = message.author.id
    message_id = message.id
    content = message.content
    channel = message.channel.id
    guild = message.guild
    if user.bot:
        return
    channel = bot.get_channel(my private log channel)
    await channel.send(f"Message ID - {message_id} **|** {user} - {user_id} **|** {content} **|** #{channel} - {guild}")
    await bot.process_commands(message)

最佳答案

您使用了两次相同的变量channel

只需重命名其中的一个即可


以下是更改两行的示例:

@bot.event
async def on_message(message):
    user = message.author
    user_id = message.author.id
    message_id = message.id
    content = message.content
    message_channel = message.channel.id
    guild = message.guild
    if user.bot:
        return
    channel = bot.get_channel(my private log channel)
    await channel.send(f"Message ID - {message_id} **|** {user} - {user_id} **|** {content} **|** #{message_channel} - {guild}")
    await bot.process_commands(message)

关于python - message.channel.id Discord PY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64472585/

相关文章:

python - 如何在 Python 中进行异步 gRPC 调用?

django - Django 测试用例中的 IntegrityError

python - Python 3.6.0 中类内的方法是非本地的

python - 为什么 on_message() 停止命令工作?

python - 这个 Numpy 形状是什么意思?

python - 如何使用 python 将多个数据帧写入 Excel 并使用 Streamlit 下载结果?

python - Discord.py --> channel.mention

discord - create_task = asyncio.async : SyntaxError: invalid syntax

python - 获取方向 pytesseract Python3

python - 如何在不使用 .split 和 .strip 函数的情况下编写我自己的拆分函数?