“NoneType"对象没有“发送"属性 - Discord Bot [英] 'NoneType' object has no attribute 'send' - Discord Bot

查看:15
本文介绍了“NoneType"对象没有“发送"属性 - Discord Bot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过 DM 向我的不和谐机器人提供命令!say"时,我正在尝试让我的不和谐机器人向我的服务器中的频道发送消息.

What I'm trying to do is to make my discord bot send a message to a channel in my server when I supply it the command "!say" through DM.

我尝试了很多不同的代码,但通常以属性错误X 对象没有属性 Y"结束

I've tried a lot of different codes, but usually, it ends up with the Attribute Error "X object has no attribute Y"

from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.command()
async def say(ctx):
    channel = bot.get_channel('584307345065246725')
    await channel.send(ctx)

当我 DM 机器人时,总是会出现错误消息,期待它发送所需的消息.

The error message always shows up when I DM the bot, expecting for it to send the required message.

推荐答案

频道id是int,不是string

The channel id is an int, not a string

@bot.command()
async def say(ctx):
    channel = bot.get_channel(584307345065246725)
    await channel.send(ctx)

我不太明白为什么你不能这样做:

What I didn't quite understand is why you couldn't just do:

from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.command(pass_context=True)
async def say(ctx):
    await ctx.send(ctx)

但是我可能弄错了你要做什么.

But I could be mistaken about what you are trying to do.

这篇关于“NoneType"对象没有“发送"属性 - Discord Bot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆