python - 不和谐 : How to get channel object where new member joined?

标签 python python-3.x discord.py

我想制作一个机器人,向 channel 中的新人发送消息。 我正在使用discord.py。

------------第二天--------------------

首先谢谢三位!(抱歉英语不好)。我学了很多。

但不幸的是,我发现“member.server.defaul_channel”(这一定是这个问题的答案)不再存在于此网址中: Discord.py Invalid arguments inside member.server_default_channel

那么,如何向现在出现新人的 channel 发送提及呢?

1,我知道一个方法,就是指定 channel 名称。

@client.event
async def on_member_join(member):
    server = member.server
    channel = [channel for channel in client.get_all_channels() if channel.name == 'WRITE_YOUR_CHANNEL_NAME!!'][0]
    message = 'hello {}, welcome to {}'.format(member.mention, server.name)
    await client.send_message(channel, message)

2,但我想知道更通用的方法。例如使用“default_channel”。有办法吗?

最佳答案

您可以使用on_member_join 事件。

每次成员加入服务器时,以下内容都会向“常规” channel 发送一条消息。

@client.event
async def on_member_join(member):
    for channel in member.server.channels:
        if channel.name == 'general':
            await client.send_message(channel, 'Message to send when member joins')

如果您想检查其他 channel 属性而不是名称,请检查以下文档。

http://discordpy.readthedocs.io/en/latest/api.html#discord.Channel

请注意,我尝试使用channel.is_default,但这总是返回False

关于python - 不和谐 : How to get channel object where new member joined?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49025833/

相关文章:

python - 适用于linux ssh命令的python ssh脚本

python - manage.py 会改变它的 PID 吗?

python - Pandas:将组转换为 json 列表,而不使用 groupby 或 apply

python - 在 f 字符串内循环作为嵌入的值

python - ModuleNotFoundError : No module named 'discord'

python - 导入过滤器 - 类型错误 : type() doesn't support MRO entry resolution

python - 在脚本结束时从 Python 3.5 切换到 2.7?

python-3.x - 如何在python中制作词频矩阵

python - 是否有一种节省内存的方法将零列和行插入 numpy 数组?

python - 类型错误 : 'bool' object is not iterable