我想使用机器人在我的私人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有关吗?
我一直在研究一些有关如何制作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) 我希望我的机器人在 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)