【问题标题】:Sending message in discord using bot使用机器人发送不和谐的消息
【发布时间】:2020-07-09 09:39:05
【问题描述】:

我在处理 discord.py 时遇到了错误 AttributeError: 'NoneType' object has no attribute 'send'

这里是代码

import discord
from discord.ext import commands

pybot=commands.Bot(command_prefix="#", description="I love it",case_insensitive=True)

log_channel_id=674175630916583445

@pybot.event

async def on_ready():
    print(f"Logged in as{pybot.user}")
    channel = pybot.get_user(log_channel_id)
    await channel.send('????')

pybot.run(TOKEN, bot=True, reconnect=True)

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您想获得一个频道,但您正在使用get_user 函数。由于机器人无法找到具有频道 ID 的用户,因此它返回 None。 替换

    channel = pybot.get_user(log_channel_id)
    

    channel = pybot.get_channel(log_channel_id)
    

    【讨论】:

      【解决方案2】:
      @pybot.event
      async def on_ready():
          print(f"Logged in as{pybot.user}")
          channel = pybot.get_channel(674175630916583445)
          await channel.send('?')
      

      您可以在 Discord.py 官方文档中获得有关 get_channel 的更多信息

      【讨论】:

        猜你喜欢
        • 2021-04-03
        • 2022-11-02
        • 2020-11-12
        • 1970-01-01
        • 2019-12-10
        • 2020-12-18
        • 2021-08-07
        • 2020-05-11
        • 2021-06-30
        相关资源
        最近更新 更多