相关疑难解决方法(0)

如何使用discordgo获取所有频道的列表?

我想使用机器人在我的私人discord服务器的所有文本频道上发送消息.

我已连接并且可以有一个Session对象,但我不知道如何从中获取所有可用频道的列表Session.

dg, err := discordgo.New("Bot " + Token)
if err != nil {
    fmt.Println("error creating Discord session,", err)
    return
}

// Open a websocket connection to Discord and begin listening.
err = dg.Open()
if err != nil {
    fmt.Println("error opening connection,", err)
    return
}

// Get all channel ID's from dg here
Run Code Online (Sandbox Code Playgroud)

这与discord API有关吗?

go discord

6
推荐指数
1
解决办法
1055
查看次数

Bot和Client有什么区别?

我一直在研究一些有关如何制作Discord Python Bot的示例,并且已经看到client并且bot几乎可以互换使用,而我找不到要在何时使用哪个。

例如:

client = discord.Client()
@client.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    if message.content.startswith('$guess'):
        await client.send_message(message.channel, 'Guess a number between 1 to 10')

    def guess_check(m):
        return m.content.isdigit()

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

client.run('token')
Run Code Online (Sandbox Code Playgroud)

bot = commands.Bot(command_prefix='?', description=description)
@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')

@bot.command()
async def add(left : int, right : …
Run Code Online (Sandbox Code Playgroud)

python discord discord.py

4
推荐指数
1
解决办法
1420
查看次数

在 on_ready 中发送消息?Python不和谐机器人

我希望我的机器人在 on_ready 事件中上线时发送一条消息。该行在 (on_message) 中工作,但我无法使其在 (on_ready) 中发送某些内容

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
    await message.channel.send('The bot is online ')
Run Code Online (Sandbox Code Playgroud)

python bots python-asyncio discord

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

discord ×3

python ×2

bots ×1

discord.py ×1

go ×1

python-asyncio ×1