首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我的机器人不把消息发送到特定的频道?Discord.py通道= bot.get_channel()

为什么我的机器人不把消息发送到特定的频道?Discord.py通道= bot.get_channel()
EN

Stack Overflow用户
提问于 2022-02-15 11:01:54
回答 1查看 772关注 0票数 0

不和谐机器人不向指定信道发送消息

你好,

我正在创建一个不和谐的机器人来记录操作并将它们发送到特定的频道。每次我运行我的代码,我没有错误,但我一输入命令/字使用,我就会得到一个错误。我只是想把行动记录到另一个频道。

我还没准备好这一节:

代码语言:javascript
运行
复制
bot = discord.ext.commands.Bot(command_prefix = "$");

这是我的代码:

代码语言:javascript
运行
复制
import os
import discord

from discord.ext import commands

bot = discord.ext.commands.Bot(command_prefix = "$");

client = discord.Client()

# @client.event
# async def on_message(message):
#  id = client.get_guild(940403791092670464)

@client.event
async def on_ready():
    print(f"{client.user} logged in now!")

@client.event
async def on_message(message):
    if message.content.startswith("$help"):
      response = print (f"@help command was used")
      await message.channel.send(f"{message.author.mention} help stuff")
    elif "fudge" in message.content:
      await message.delete()
      response = print(f"You're not allowed to say those words {message.author.mention} Word Used: Fudge")
      await message.channel.send(f"You're not allowed to use those words {message.author}.")      
    elif "female dog" in message.content:
      channel = bot.get_channel(943040534165991485)
      await channel.send(f"{message.author.mention} Said the word female dog.")
      await message.channel.send(f"You're not allowed to say those words {message.author.mention}")
      await message.delete()
      response = print (f"Logging actions.")

my_secret = os.environ['TOKEN']
client.run(my_secret)

这是我的错误:

on_message

  • Traceback (最近一次调用)中的
  • 忽略异常:
    • File "/home/runner/Discord-Bot/venv/lib/python3.8/site-packages/discord/client.py",第343行,在_run_event中等待coro(*args,**kwargs)

)

  • 文件"main.py",第31行,on_message
    • on_message channel.send(f"{message.author.mention} Said the word on_message
      • channel.send)“

  • AttributeError:'NoneType‘对象没有属性'send'

任何事都有帮助!

EN

回答 1

Stack Overflow用户

发布于 2022-02-15 13:41:37

使用fetch_channel()而不是get_channel()。在discord.py中,作为一项经验规则,fetch_something()进行API调用,而get_something()试图从缓存中获取它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71125299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档